-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
129 lines (115 loc) · 3.09 KB
/
webpack.config.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const path = require("path");
const PROD = process.env.NODE_ENV === "production";
module.exports = {
// Defaults to development, pass --mode production to override
mode: "development",
context: path.resolve(__dirname, "src"),
target: "web",
entry: {
app: "./index.jsx",
},
output: {
filename: "[name].[hash:7].js",
path: path.resolve(__dirname, "build"),
publicPath: PROD ? "./" : "/",
},
module: {
rules: [
{
test: /\.(css|scss)$/,
use: [
"style-loader",
{
loader: "css-loader",
options: { modules: true, importLoaders: 1 },
},
{ loader: "postcss-loader", options: { sourceMap: "inline" } },
],
},
// Escape hatch for CSS module classname mangling
{
test: /\.legacy\.(css|scss)$/,
include: path.resolve(__dirname, "src"),
use: [
"style-loader",
{ loader: "css-loader", options: { importLoaders: 1 } },
],
},
{
test: /\.(jpg|png|gif|mp4|webm|mp3|ogg)$/,
loader: "file-loader",
options: {
name: "./f/[path][name].[hash].[ext]",
},
},
{
test: /\.jsx?$/,
exclude: /\/node_modules\//,
loader: "babel-loader",
options: {
plugins: [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
["@babel/plugin-proposal-class-properties", { loose: false }],
"@babel/plugin-proposal-json-strings",
],
presets: ["@babel/preset-react", "@babel/preset-flow"],
},
},
// {
// test: /\.tsx?$/,
// exclude: /\/node_modules\//,
// loader: "babel-loader",
// options: {
// plugins: ["@babel/proposal-object-rest-spread"], // Needed for jsx interop
// presets: ["@babel/react", "@babel/preset-typescript"]
// }
// }
],
},
plugins: [
new HtmlWebpackPlugin({
files: {
css: [],
js: ["[name].js", "commons.js"],
},
template: "./index.html",
}),
...(PROD ? [new CompressionPlugin()] : []),
],
// optimization: {
// splitChunks: {
// cacheGroups: {
// commons: {
// test: /[\\/]node_modules[\\/]/,
// filename: "commons.js",
// name: "commons",
// chunks: "all"
// }
// }
// }
// },
devtool: "source-map",
devServer: {
historyApiFallback: true,
},
externals: {
cheerio: "window",
"react/addons": true,
"react/lib/ExecutionEnvironment": true,
"react/lib/ReactContext": true,
fs: "commonjs fs", // required for rustc generated JS-WASM loader
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx", ".wasm"],
modules: ["node_modules", path.resolve(__dirname, "src")],
alias: {
"@src": path.resolve(__dirname, "src"),
},
},
experiments: {
syncWebAssembly: true,
},
};