-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.mjs
116 lines (114 loc) · 2.67 KB
/
webpack.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* eslint-disable import/no-anonymous-default-export */
/* eslint-disable global-require */
import { fileURLToPath } from "url";
import path, { dirname } from "path";
import webpack from "webpack";
import CopyPlugin from "copy-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";
const webpackConfig = (_) => ({
entry: "./src/index.tsx",
resolve: {
extensions: [".ts", ".tsx", ".js"],
modules: [
path.resolve(dirname(fileURLToPath(import.meta.url)), "src"),
"node_modules",
],
plugins: [new TsconfigPathsPlugin()],
},
output: {
filename: "build.js",
path: path.join(dirname(fileURLToPath(import.meta.url)), "build"),
clean: true,
publicPath: "/",
},
devServer: {
port: 3000,
host: "0.0.0.0",
allowedHosts: "all",
historyApiFallback: true,
watchFiles: {
paths: "src/**/*",
options: {
poll: true,
},
},
static: path.join(dirname(fileURLToPath(import.meta.url)), "public"),
client: {
webSocketURL: "ws://0.0.0.0/ws",
},
},
module: {
rules: [
{
test: /\.js$/,
include: new URL("./src", import.meta.url).pathname,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
targets: "defaults",
},
],
"@babel/preset-react",
],
},
},
],
},
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
transpileOnly: true,
},
exclude: /dist/,
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: "url-loader",
options: {
limit: 25000,
},
},
],
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: "file-loader",
},
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: "asset/resource",
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: "./public/index.html",
}),
new ForkTsCheckerWebpackPlugin({}),
new webpack.ProvidePlugin({
React: "react",
}),
new CopyPlugin({
patterns: [
{ from: "*.png", to: "", context: "public" },
{ from: "*.json", to: "", context: "public" }
]
})
],
});
export default webpackConfig;