ZachJW34 / nx-plus

Collection of Nx Community Plugins
MIT License
302 stars 50 forks source link

Have you been able to run the bundle analyzer plugin? #259

Closed gregveres closed 2 years ago

gregveres commented 2 years ago

When I configure webpack to use the bundle analyzer plugin, nothing happens. I get can get it to create the json file, but normally after the build, the analyzer plugin starts. But when running under nx-plus/vue, that doesn't happen.

I was wondering if you guys had tried to use it or not.

gregveres commented 2 years ago

I must have done something wrong the first time I tried it.

With this configuration:

const WebpackAssetsManifest = require('webpack-assets-manifest');
//const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const StatoscopeWebpackPlugin = require('@statoscope/webpack-plugin').default;

module.exports = {
    plugins: [
      new WebpackAssetsManifest({
        output: 'asset-manifest.json'
      })
      //, new VuetifyLoaderPlugin()
      // new webpack.IgnorePlugin({
      //   resourceRegExp: /^\.unit\.ts$/,
      //   contextRegExp: /.*/
      // })
    // , new StatoscopeWebpackPlugin({ analyzerMode: 'json', openAnalyzer: true,  generateStatsFile: true })
      , new BundleAnalyzerPlugin({ openAnalyzer: true,  generateStatsFile: true })
    ]
  }

the analyzer window opens after the build is complete.

I also found that you can run the UI on the generated stats file whenver you want by adding this to your package.json scripts section:

    "analyze": "webpack-bundle-analyzer dist/apps/<app>/stats.json"