-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
43 lines (36 loc) · 1.02 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
const TerserJSPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const helpers = require("./webpack/helpers");
const webpackConfig = require("./webpack/config");
module.exports = (env, options) => {
const isProduction = options.mode === "production";
if (isProduction) {
webpackConfig.optimization.minimizer.push(
new TerserJSPlugin({
include: /\.min\./,
}),
new OptimizeCSSAssetsPlugin({
assetNameRegExp: /\.min\.css$/g,
}),
);
} else {
webpackConfig.devtool = "#eval-source-map";
}
const entryFilesOutputPathMappings = helpers.getSourceOutputMappings(isProduction);
return Object.entries(entryFilesOutputPathMappings).map(mappings => {
const entry = {
main: mappings[0],
};
if (isProduction) {
entry["main.min"] = entry.main;
}
return {
entry,
output: {
path: mappings[1],
filename: '[name].js'
},
...webpackConfig,
}
});
}