forked from plone/volto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack-bundle-analyze-plugin.js
40 lines (33 loc) · 1.09 KB
/
webpack-bundle-analyze-plugin.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
/**
* An adaptation of MIT licensed for Razzle ^3.3
* https://github.com/nimacsoft/razzle-plugin-bundle-analyzer
*/
const offline = process.env.OFFLINE_BUNDLE_ANALYZE === 'true' ? true : false;
const defaultOptions = {
concatenateModules: false,
analyzerHost: '0.0.0.0',
analyzerMode: offline ? 'static' : 'server',
generateStatsFile: true,
statsFilename: 'stats.json',
reportFilename: 'reports.html',
openAnalyzer: offline ? false : true,
};
function modifyWebpackConfig({
env: { target, dev },
webpackConfig: config,
webpackObject,
options: { pluginOptions, razzleOptions, webpackOptions },
}) {
const options = Object.assign({}, defaultOptions, pluginOptions);
if ((process.env.BUNDLE_ANALYZE === 'true' || offline) && target === 'web') {
const { concatenateModules, ...bundleAnalyzerOptions } = options;
config.optimization.concatenateModules = concatenateModules;
config.plugins.push(
new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)(
bundleAnalyzerOptions,
),
);
}
return config;
}
module.exports = { modifyWebpackConfig };