webpack-bundle-analyzer icon indicating copy to clipboard operation
webpack-bundle-analyzer copied to clipboard

Multi-compiler support

Open gpoitch opened this issue 7 years ago • 7 comments

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

gpoitch avatar Nov 04 '16 14:11 gpoitch

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?

mkarajohn avatar Nov 06 '16 00:11 mkarajohn

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.

gpoitch avatar Nov 06 '16 16:11 gpoitch

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.

valscion avatar Jan 29 '17 13:01 valscion

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.

valscion avatar Mar 06 '18 15:03 valscion

Use the port 0 for analyzerPort: 0 will auto choose the port

mems avatar Jan 10 '19 16:01 mems

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;

jeffreymb avatar Jun 06 '19 13:06 jeffreymb

See https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/281 for a contribution opportunity for this issue

valscion avatar Jun 07 '19 06:06 valscion

Is it possible to view Multi-compiled bundles in Single view now using this plugin?

kritidipto-1234 avatar Apr 14 '23 15:04 kritidipto-1234

No, one view per one bundle. I don't think it's feasible to support more than one bundle in one visualization.

valscion avatar Apr 14 '23 16:04 valscion