This repository has been archived by the owner on Dec 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathwebpack.config.js
81 lines (72 loc) · 2.27 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
const webpack = require("webpack");
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const StringReplacePlugin = require("string-replace-webpack-plugin");
const UNASSERT_RULE = {
test: /\.js$/,
use: [{
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /\n[ \t]*assert(\.[a-zA-Z0-9_]+)?\([^\);]+[\)\s]+[ \t]*[;\n]/g,
replacement: function (match, p1, offset, string) {
//strip
return "";
}
}
]
})
}]
};
module.exports = (env, argv) => {
const moduleRules = [];
const plugins = [];
const defines = {
ENV_PRODUCTION: false
};
if (argv.mode === 'production') {
defines.ENV_PRODUCTION = true;
moduleRules.push(UNASSERT_RULE);
plugins.push(new StringReplacePlugin())
}
plugins.push(new webpack.DefinePlugin(defines));
return {
entry: './src/demo.js',
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js'
},
plugins,
module: {
rules: moduleRules
},
//resolution configuration
resolve: {},
node: { module: "empty", net: "empty", fs: "empty" },
optimization: {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: false, // Must be set to true if using source-maps in production
terserOptions: {
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
compress: {
passes: 3,
keep_infinity: true
}
}
}),
],
},
devtool: "source-map",
//mode values: [production, development]
mode: 'development',
devServer: {
contentBase: path.join(__dirname, 'public'),
compress: true,
port: 9000
}
};
};