project is too large, the compilation will be very slow. Every time I start a new project, it will climb at the same speed. I cannot help but want to optimize the compilation speed

Analyze the project with speed-measure-webpack-plugin and webpack-bundle-analyzer
image.png

Optimization

Cache optimization
hard-source-webpack-plugin, this plug-in provides intermediate caching steps for modules, but the project has to be run twice. The first build time is normal, and the second time can save about 90% of the time.
npm i hard-source-webpack-plugin -D

plugins: [
  new HardSourceWebpackPlugin()
]

But there is no independent webpack.config.js file in the project, so it can only be placed in the vue.config.js file, and use chainWebpack to insert the configuration into webpack.
Use cache in the official website
image.png

chainWebpack: (config) => {
  config.cache(true)
}

Cooperate with HardSourceWebpackPlugin

chainWebpack: (config) => {
  config.plugin('cache').use(HardSourceWebpackPlugin)
}

HappyCodingTop
526 声望847 粉丝

Talk is cheap, show the code!!