Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack 性能分析 #14

Open
maomao1996 opened this issue Nov 10, 2020 · 0 comments
Open

Webpack 性能分析 #14

maomao1996 opened this issue Nov 10, 2020 · 0 comments
Labels
CLI 脚手架配置相关 React react 相关 Vue vue 相关 Webpack Webpack 相关

Comments

@maomao1996
Copy link
Owner

maomao1996 commented Nov 10, 2020

Webpack 性能分析

打包速度分析 speed-measure-webpack-plugin

yarn add -D speed-measure-webpack-plugin
# OR
npm install -D speed-measure-webpack-plugin

speed-measure-webpack-plugin | GitHub

create-react-app

react-app-rewired + customize-cra 方案

修改 config-overrides.js 文件

const { override } = require('customize-cra')
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
const smp = new SpeedMeasurePlugin()
const customWebpackConfig = (config) => smp.wrap(config)

module.exports = override(customWebpackConfig)

vue-cli 4.x

修改 vue.config.js 文件

const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
const smp = new SpeedMeasurePlugin()

// 方案一
module.exports = {
  configureWebpack: (config) => {
    // 其他配置
    smp.wrap(config)
  }
}

// 方案二
module.exports = {
  configureWebpack: smp.wrap({})
}

打包体积分析 webpack-bundle-analyzer

yarn add -D webpack-bundle-analyzer
# OR
npm install -D webpack-bundle-analyzer

webpack-bundle-analyzer | GitHub

create-react-app

react-app-rewired + customize-cra 方案

修改 config-overrides.js 文件

const { override, addBundleVisualizer } = require('customize-cra')

module.exports = override(addBundleVisualizer)

create-react-app 官方推荐使用 source-map-explorer

vue-cli 4.x

修改 vue.config.js 文件

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

module.exports = {
  chainWebpack(config) {
    config.plugin('webpack-bundle-analyzer').use(BundleAnalyzerPlugin)
  }
}
@maomao1996 maomao1996 added CLI 脚手架配置相关 React react 相关 Vue vue 相关 Webpack Webpack 相关 labels Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI 脚手架配置相关 React react 相关 Vue vue 相关 Webpack Webpack 相关
Projects
None yet
Development

No branches or pull requests

1 participant