-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
51 lines (45 loc) · 1.26 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
const { mode } = require("webpack-nano/argv")
const { merge } = require("webpack-merge")
const parts = require("./webpack.parts");
const path = require("path");
const commonConfig = merge([
{
entry: "./src/index.js"
},
{
output: {
path: path.resolve(__dirname, "dist"),
libraryTarget: "var",
library: "$",
assetModuleFilename: "images/[name][ext]"
},
},
parts.clean(),
parts.page(),
parts.extractCSS(),
parts.loadJavaScript(),
parts.loadImages(),
]);
const productionConfig = merge([
parts.minifyJavaScript(),
parts.minifyCSS({ options: { minimizerOptions: { preset: ["default", { discardComments: { removeAll: true } }] } } }),
parts.serviceWorker(),
]);
const developmentConfig = merge([
{
entry: [
"webpack-plugin-serve/client", "./src/index.js"]
},
parts.devServer(),
]);
const getConfig = (mode) => {
switch (mode) {
case "production":
return merge(commonConfig, productionConfig, { mode });
case "development":
return merge(commonConfig, developmentConfig, { mode });
default:
throw new Error(`Unknown mode: ${mode}`);
}
};
module.exports = getConfig(mode);