webpack-bundle-analyzer 使用

陶英达
2023-12-01

安装

# NPM 
npm install --save-dev webpack-bundle-analyzer
# Yarn 
yarn add -D webpack-bundle-analyzer

配置

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const path = require('path');

const rootPath = path.join(__dirname);
module.exports = {
  entry: {
    main: `${rootPath}/src/index.js`,
  },
  output: {
    filename: '[name].[hash].js',
    path: `${rootPath}/dist`,
  },
  plugins: [
    new BundleAnalyzerPlugin()
  ]
}

运行

# 当前项目下安装webpack
 ./node_modules/.bin/webpack --config webpack.config.js --progress
# or
# 全局安装webpack
webpack --config webpack.config.js --progress
 类似资料: