-
Notifications
You must be signed in to change notification settings - Fork 47
/
webpack.config.js
77 lines (70 loc) · 1.73 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
const { mode } = require("webpack-nano/argv");
const { merge } = require("webpack-merge");
const path = require("path");
const parts = require("./webpack.parts");
const cssLoaders = [parts.autoprefix(), parts.tailwind()];
const commonConfig = merge([
{
resolveLoader: {
alias: {
"demo-loader": path.resolve(__dirname, "loaders/demo-loader.js"),
},
},
},
{
output: {
// Tweak this to match your GitHub project name
publicPath: "/",
},
},
{ entry: ["./src"] },
parts.page({ title: "Demo" }),
parts.clean(),
parts.extractCSS({ loaders: cssLoaders }),
parts.loadImages({
limit: 15000,
}),
parts.loadJavaScript(),
parts.setFreeVariable("HELLO", "hello from config"),
]);
const productionConfig = merge([
{
output: {
chunkFilename: "[name].[contenthash].js",
filename: "[name].[contenthash].js",
assetModuleFilename: "[name].[contenthash][ext][query]",
},
recordsPath: path.join(__dirname, "records.json"),
},
parts.minifyJavaScript(),
parts.minifyCSS({
options: {
preset: ["default"],
},
}),
parts.eliminateUnusedCSS(),
parts.generateSourceMaps({ type: "source-map" }),
{
optimization: {
splitChunks: {
chunks: "all",
},
runtimeChunk: {
name: "runtime",
},
},
},
parts.attachRevision(),
]);
const developmentConfig = merge([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(`Trying to use an unknown mode, ${mode}`);
}
};
module.exports = getConfig(mode);