webpack-bundle-analyzer
webpack-bundle-analyzer copied to clipboard
Multi-compiler support
For webpack configs that return arrays, only one of the bundles has a report generated.
Throws an EADDRINUSE in server mode, presumably trying to launch both.
EDIT: does work correctly in 'static' mode.
Edit by @valscion
Help contribute a fix for this issue here: https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/281
I have a webpack.config
that exports 4 other configs. I am using the plugin in each one of them separately and I get 4 report pages. How are you using it?
Essentially just this (stripped down) webpack.config.js:
module.exports = function () {
const config1 = {
// ...
plugins: [new BundleAnalyzerPlugin()]
}
const config2 = {
// ...
plugins: [new BundleAnalyzerPlugin()]
}
return [config1, config2]
}
It tries to start 2 servers and crashes Error: listen EADDRINUSE :::8888
.
Fixable by defining a different analyzerPort
for each.
Feel free to close, but might be fixable to work out of the box.
One way to do this is exactly to set a different analyzerPort
for each instance, or if using static
mode, to set different reportFilename
options for each instance.
The way assets-webpack-plugin
works in multi-compiler mode is by only creating one instance of the plugin and adding that instance to the plugins
array: https://github.com/kossnocorp/assets-webpack-plugin/tree/v3.5.1#using-in-multi-compiler-mode
That could be a way to support multi-compiler mode in the future, as long as the implementation of this plugin would support it. Right now it doesn't seem to be so, as the reporter cannot combine results from multiple 'done'
plguin events yet.
I wonder if https://www.npmjs.com/package/port-authority might be useful here. We could try finding a port starting from the default value if a specific value is not set.
Use the port 0 for analyzerPort: 0
will auto choose the port
I solved this with the following:
const configs = [
appConfig,
publicConfig,
pdfAssets,
];
for (let i = 0; i < configs.length; i++) {
configs[i].plugins.push(new BundleAnalyazerPlugin({
// different port for each config to prevent collision.
analyzerPort: 8888 + i,
}));
}
return configs;
See https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/281 for a contribution opportunity for this issue
Is it possible to view Multi-compiled bundles in Single view now using this plugin?
No, one view per one bundle. I don't think it's feasible to support more than one bundle in one visualization.