node.jswebpacktree-shaking

How can I see a list of packages actually used for my application bundle?


I have a problem in treeshaking. It seems like it is not too effective on my project. Is there a way to see a list of the dependencies that is actually used in my webpacked file?

Webpack config:

entry: sourceEntryFile,
  mode: 'production', // for webpack 4
  target: 'node',
  output: {
    filename: '[name].js',
    path: outputPathFolder,
    libraryTarget: 'commonjs',
  },
  resolve: {
    extensions: ['.js', '.json'],
    modules: ['node_modules']
  },
  node: {
    __dirname: false,
  },
  externals: {
    'aws-sdk': 'aws-sdk'
  },
  plugins: (() => {
    const plugins = [
      new webpack.DefinePlugin({
        'global.GENTLY': false
      })
    ];
    // plugins.push(new WebpackBundleAnalyzer.BundleAnalyzerPlugin());
    return plugins;
  })()

Solution

  • npm ls seems to be the closest one. The results show which modules are being used in current project.