1:webpack5 之 优化效率工具 进度条
方式1
package.json
"devDependencies": {
"progress-bar-webpack-plugin": "^2.1.0"
},
webpack.base.js
const path = require('path')
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
module.exports = {
entry: {
main: './src/main.js'
},
output: {
publicPath: '',
path: path.resolve(__dirname, '../dist'),
filename: 'js/[name]_[contenthash:6].js',
},
plugins: [
new ProgressBarPlugin()
]
}
效果
方式2与3 ( 推荐 方式2 )
package.json
"devDependencies": {
"webpackbar": "^5.0.2"
},
webpack.base.js
const path = require('path')
const WebpackBar = require('webpackbar');
module.exports = {
entry: {
main: './src/main.js'
},
output: {
publicPath: '',
path: path.resolve(__dirname, '../dist'),
filename: 'js/[name]_[contenthash:6].js',
},
plugins: [
new WebpackBar({
basic: false,
profile: false,
})
]
}
效果
- 方式2
2:webpack5 之 优化效率工具 速度分析
package.json
"devDependencies": {
"speed-measure-webpack-plugin": "^1.5.0"
},
webpack.dev.js
const merge = require('webpack-merge')
const baseConfig = require('./webpack.base');
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const smp = new SpeedMeasurePlugin();
const devPlugingConfig = smp.wrap({
})
const devConfig = {
mode: 'development',
devtool: 'eval-cheap-module-source-map',
cache: {
type: 'memory'
},
devServer: {
port: '3001',
hot: true,
compress: true,
proxy: {
'/api': {
target: 'http://0.0.0.0:80',
pathRewrite: {
'/api': '',
},
},
},
}
}
module.exports = merge(baseConfig, devConfig, devPlugingConfig)
npm run dev 效果
3:webpack5 之 优化效率工具 打包后提交分析
package.json
"devDependencies": {
"webpack-bundle-analyzer": "^4.6.1"
},
webpack.pro.js
const path = require('path')
const merge = require('webpack-merge');
const baseConfig = require('./webpack.base');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const proConfig = {
mode: 'production',
devtool: 'hidden-source-map',
cache: {
type: 'filesystem',
buildDependencies: {
config: [__filename]
}
},
plugins: [
new BundleAnalyzerPlugin()
]
}
module.exports = merge(baseConfig, proConfig)
打包后体积分析 ( npm run build效果 自动开启一个网站 )
|