-
Notifications
You must be signed in to change notification settings - Fork 17
/
webpack.config.prod.js
123 lines (114 loc) · 4 KB
/
webpack.config.prod.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
const merge = require("webpack-merge");
const webpack = require("webpack");
const path = require("path");
const baseConfig = require("./node_modules/@mendix/pluggable-widgets-tools/configs/webpack.config.prod.js");//Can also be webpack.config.prod.js
const pkg = require('./package.json');
const TerserPlugin = require("terser-webpack-plugin");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const args = process.argv.slice(2);
// We're doing dirty hacking, because our camel case stuff doesn't transpile nicely to ES5. Need another solution, but this works in IE11
// TODO: Just use my own config
baseConfig[0].module.rules[1].exclude = /node_modules\/(?!(filesize)\/).*/
baseConfig[0].module.rules[1].use.options.presets[0] = [
'@babel/preset-env',
{
"targets": {
"browsers": ["last 2 versions", "ie >= 11"],
},
"modules": false,
// "useBuiltIns": "usage",
// "corejs": "3"
}
]
// baseConfig[1].module.rules[1].exclude = /node_modules\/(?!(@thi.ng)\/).*/
baseConfig[1].module.rules[1].use.options.presets[0] = [
'@babel/preset-env',
{
"targets": {
"browsers": ["last 2 versions", "ie >= 11"],
},
"modules": false,
// "useBuiltIns": "usage",
// "corejs": "3"
}
]
baseConfig[1].module.rules[0].options = { transpileOnly: true }
const terserPlugin = new TerserPlugin({
cache: true,
parallel: true,
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {
passes: 2
},
mangle: true, // Note `mangle.properties` is `false` by default.
module: false,
output: {
comments: false,
beautify: false,
preamble: `/* FileDropper for Mendix || Version ${pkg.version} || Apache 2 LICENSE || Developer: ${pkg.author} || Please report any issues here: https://github.com/mendixlabs/mendix-file-dropper/issues */\n`
// comments: false
},
toplevel: false,
nameCache: null,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
safari10: false,
},
});
const customConfig = {
// Custom configuration goes here
devtool: false,
optimization: {
minimizer: [
terserPlugin
]
},
plugins: [
// We only include the moment locale for en-gb, as this is not used in a lot of places and we don't need all the locales
// new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb/)
],
// We add this to further slim down the package
resolve: {
extensions: [".mjs", ".json", ".ts", ".js", ".tsx", ".jsx"],
alias: {
"react-icons/fa": path.join(__dirname, "node_modules/react-icons/fa/index.esm"),
"react-icons/ti": path.join(__dirname, "node_modules/react-icons/ti/index.esm"),
//"filesize": path.join(__dirname, "node_modules/filesize/lib/filesize.esm.js")
}
}
};
if (args.length === 5 && args[4] === "--analyze") {
customConfig.plugins.push(new BundleAnalyzerPlugin());
}
const previewConfig = {
// Custom configuration goes here
// devtool: false,
// plugins: [
// ],
// optimization: {
// // minimizer: [
// // terserPlugin
// // ]
// },
resolve: {
extensions: [".mjs", ".json", ".ts", ".js", ".tsx", ".jsx"],
alias: {
"react-icons/fa": path.join(__dirname, "node_modules/react-icons/fa/index.esm"),
"react-icons/ti": path.join(__dirname, "node_modules/react-icons/ti/index.esm"),
//"filesize": path.join(__dirname, "node_modules/filesize/lib/filesize.esm.js")
}
},
externals: [
/^mendix\//,
"react",
"react-dom"
]
};
if (args.length === 5 && args[4] === "--analyze") {
// previewConfig.plugins.push(new BundleAnalyzerPlugin());
}
module.exports = [merge(baseConfig[0], customConfig), merge(baseConfig[1], previewConfig)];