Overview:
The article provides a guide on how to upgrade a webpack + Vue multi-page project to webpack 4 and optimize its build speed. The author explains the process of upgrading webpack, installing necessary dependencies, and optimizing the build speed by using plugins and techniques such as parallel processing and DLL packaging. The article also covers adding ES6+ support with Babel 7.
Features:
- Webpack 4 Upgrade: Steps to upgrade webpack to version 4, including installing necessary dependencies and modifying configurations.
- Build Speed Optimization: Techniques and plugins to optimize the build speed, such as parallel processing, using TerserPlugin, and pre-packaging common code.
- ES6+ Support: Steps to add ES6+ support to the project using Babel 7, including installing dependencies and configuring Babel plugins and presets.
Installation:
To upgrade a webpack + Vue multi-page project to webpack 4 and optimize its build speed, follow these steps:
Webpack 4 Upgrade:
- Upgrade and install necessary dependencies:
webpack-cliwebpack 4.xmini-css-extract-plugin(replacesextract-text-webpack-plugin)- Other related loaders and plugins such as
css-loader,file-loader,url-loader,vue-style-loader, andvue-template-compiler
- Modify the configuration:
- Set the build mode in the
modeoption - Replace the
extract-text-webpack-pluginconfiguration with themini-css-extract-pluginconfiguration - Use the
optimizationoption to configure file splitting - Upgrade
vue-loaderto version 15 and use a webpack plugin for proper usage - Upgrade
html-webpack-pluginto thenextversion for resource file injection - Compress files using
optimize-css-assets-webpack-pluginandterser-webpack-plugin
- Set the build mode in the
- Upgrade and install necessary dependencies:
Build Speed Optimization:
- Use the
speed-measure-webpack-pluginto analyze build time - Enable the parallel option for the
TerserPluginand usethread-loaderorHappyPackfor multi-threaded transformation of loaders - Pre-package common code using
DllPluginand update the webpack configuration to usewebpack.DllReferencePluginand manually reference the generated DLL files in HTML
- Use the
ES6+ Support:
- Install the following dependencies:
@babel/core,@babel/plugin-proposal-class-properties,@babel/plugin-proposal-decorators,@babel/plugin-syntax-dynamic-import,@babel/plugin-transform-runtime,@babel/preset-env,@babel/runtime,babel-loader, and@babel/polyfill - Configure Babel 7 by using the new namespacing
@babeland specifying options for@babel/plugin-transform-runtime
- Install the following dependencies:
Summary:
The article provides detailed steps on how to upgrade a webpack + Vue multi-page project to webpack 4 and optimize its build speed. It covers the installation of necessary dependencies, modification of webpack configurations, and usage of plugins to improve build performance. Additionally, the article explains how to add ES6+ support using Babel 7. The provided guide is a valuable resource for developers working on multi-page projects with webpack and Vue.