-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
31 lines (27 loc) · 898 Bytes
/
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
const { ContextReplacementPlugin } = require("webpack");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const { npm_package_config_excludes = "" } = process.env;
const excludes = npm_package_config_excludes
.split(",")
.map(excl => excl.trim())
.filter(excl => excl !== "");
const excludeContext = new RegExp(`^(?!.*(?:${excludes.join('|')})).*\\.op\\.js$`);
if(excludes.length){
console.info(`[INFO] Custom build detected. Excluding from bundle: ${excludes.join(', ')}`);
}
module.exports = (env = {}) => {
const { analyze = false } = env;
return {
module: {
rules: [{ test: /.js$/, use: "babel-loader" }]
},
plugins: [
analyze ? new BundleAnalyzerPlugin() : null,
new ContextReplacementPlugin(
/operations/,
excludes.length ? excludeContext : /\.op\.js$/
)
].filter(p => p)
};
};