-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
50 lines (48 loc) · 1.34 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
let webpack = require("webpack");
let path = require("path");
let HtmlWebpackPlugin = require("html-webpack-plugin");
let TerserPlugin = require("terser-webpack-plugin");
let CopyWebpackPlugin = require("copy-webpack-plugin");
let packageJson = require("./package.json");
let publicPath = process.env.PUBLIC_PATH || "/";
module.exports = {
mode: process.env.NODE_ENV == "production" ? "production" : "development",
devtool: false,
entry: {
index: "./src/App.mjs",
},
optimization: {
minimize: process.env.NODE_ENV == "production",
minimizer: [
new TerserPlugin({
parallel: false,
}),
],
},
output: {
path: path.join(__dirname, "build"),
publicPath,
filename: `public/${packageJson.version}/[name].[contenthash].js`,
chunkFilename: `public/chunks/[contenthash].js`,
globalObject: "this",
},
plugins: [
new CopyWebpackPlugin({
patterns: [{ from: "**/*", to: ``, context: "./statics" }],
}),
new HtmlWebpackPlugin({
filename: `index.html`,
template: "./src/index.html",
chunks: ["index"],
}),
// Used to simulate SPA on GitHub
new HtmlWebpackPlugin({
filename: `404.html`,
template: "./src/index.html",
chunks: ["index"],
}),
new webpack.DefinePlugin({
"process.env.PUBLIC_PATH": JSON.stringify(publicPath),
}),
],
};