-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
139 lines (117 loc) · 3.19 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
130
131
132
133
134
135
136
137
138
139
const path = require('path');
const { mode } = require("webpack-nano/argv");
const parts = require('./webpack.parts');
const { merge } = require('webpack-merge');
const cssLoaders = [parts.autoprefix(), parts.tailwind(), parts.sassCSS()];
const commonConfig = merge([
{
resolveLoader: {
alias: {
"demo-loader": path.resolve(__dirname, "loaders/demo-loader.js")
},
},
},
{
//context: path.resolve(__dirname),
//devtool: 'source-map',
//entry: ['./src'],
output: {
path: path.resolve(process.cwd(), "dist"),
publicPath: "/webpack-kit/",
}
},
//parts.page({ title: "Webpack-kit" }),
parts.clean(),
parts.extractCSS( { options: {hmr: true}, loaders: cssLoaders }),
parts.loadImages({
options: {
limit: 15000,
name: "[name].[ext]",
},
}),
parts.loadJavaScript(),
parts.setFreeVariable("HELLO", "hello from config"),
]);
const productionConfig = merge([
{
output: {
chunkFilename: "[name].[contenthash:4].js",
filename: "[name].[contenthash:4].js",
assetModuleFilename: "[name].[contenthash:4][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(),
//parts.extractCSS({ options: {hmr: true}, loaders: cssLoaders }),
])
/*
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 unknow mode, ${mode}`)
}
};
*/
const getConfig = (mode) => {
const pages = [
merge(
parts.entry({
name: 'app',
path: path.join(__dirname, "src", "index.js"),
mode
}),
parts.page({
title: "Webpack demo",
chunks: ["app", "runtime", "vendor"],
}),
),
merge(
parts.entry({
name: 'another',
path: path.join(__dirname, "src", "another.js"),
mode
}),
parts.page({
title: "Another demo",
path: "another",
chunks: ["another", "runtime", "vendor"],
}),
),
];
let config;
switch (mode) {
case "production":
config = productionConfig;
break;
case "development":
default:
config = developmentConfig;
}
return pages.map(page => merge(commonConfig, config, page, { mode }));
};
module.exports = getConfig(mode);