1. Install dependencies:

Compression -webpack-plugin is a very useful compression plugin, suitable for vue-CLI version 2 and above, must be installed with the version number, otherwise, too high may cause errors.

NPM install - save - dev [email protected]

2. Change productionGzip to true in index.js under config

3. Modify webpack.prod.conf.js in build and change assert to fileName.

4. Configuration ngnix

gzip on; gzip_buffers 4 16k; gzip_comp_level 5; gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg  image/gif image/png;Copy the code

At this point, the configuration is complete.

5. Let’s pack up. You can see that all files generate a gz file with the same name. The maximum file size is directly compressed from 1.7m to 300K, and the effect is still ok.