隨着項目越來約龐大,致使構建包的時候速度緩慢!vue
首先推薦使用wepback的可視化資源分析工具。如下給出webpack-bundle-analyzer配置【vue-cli構建項目時會自動配置好】
config/index.js文件中webpack
module.exports = { build: { ... // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report } ... }
webpack生產環境中 build/webpack.prod.conf.js文件中web
... if (config.build.bundleAnalyzerReport) { var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin webpackConfig.plugins.push(new BundleAnalyzerPlugin()) } ...
分析結果出來了,接下來就能夠開始優化啦