Webpack-bundle-analyzer: How to run bundle analyzer with Webpacker?

Created on 17 Sep 2019  Â·  5Comments  Â·  Source: webpack-contrib/webpack-bundle-analyzer

I'm having issues with running webpack bundle analyzer with webpacker.
I have such config in my environment.js:

const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');

environment.plugins.append(
  'BundleAnalyzer',
  new BundleAnalyzerPlugin(),
);

module.exports = environment;

What do I need to do next to run it? I cannot find any commands in docs

I tried commands

node_modules/.bin/webpack --config config/webpack/environment.js --profile --json > stats.json 
node_modules/.bin/webpack-bundle-analyzer stats.json

but have this error generated in stats file

/app/node_modules/webpack/bin/convert-argv.js:507
                throw new Error("'output.filename' is required, either in config file or as --output-filename");
                ^

Error: 'output.filename' is required, either in config file or as --output-filename
    at processOptions (/app/node_modules/webpack/bin/convert-argv.js:507:11)
    at processConfiguredOptions (/app/node_modules/webpack/bin/convert-argv.js:150:4)
    at module.exports (/app/node_modules/webpack/bin/convert-argv.js:112:10)
    at yargs.parse (/app/node_modules/webpack/bin/webpack.js:171:41)
    at Object.Yargs.self.parse (/app/node_modules/webpack/node_modules/yargs/yargs.js:533:18)
    at Object.<anonymous> (/app/node_modules/webpack/bin/webpack.js:152:7)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

```

Most helpful comment

All 5 comments

What is webpacker? Do you mean webpack? Then check out webpack documentation please https://webpack.js.org/guides/getting-started/#using-a-configuration

Let us know if you figure out a way — we are not capable of providing support for webpacker as neither one of us have experience in that, sorry.

In the case you're using Docker (and docker-compose), after having opened the port 8888 on the service where is running webpack, you need to update the webpack-bundle-analyzer's config so that it runs on 0.0.0.0 rather than 127.0.0.1 otherwise it is not accessible:

environment.plugins.append('BundleAnalyzer', new BundleAnalyzerPlugin({
  analyzerHost: '0.0.0.0'
}))
Was this page helpful?
0 / 5 - 0 ratings