NPM install compression will – webpack – the plugin

npm install compression-webpack-plugin --save-dev
Copy the code

vue.config.js

const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
    configureWebpack: (function () {
    if (process.env.NODE_ENV === 'production') {
      return {
        plugins: [
          // new MyAwesomeWebpackPlugin()
          new CompressionPlugin({
            algorithm: 'gzip'.// Use gzip compression
            test: /\.js$|\.html$|\.css$/.// Match the file name
            filename: '[path].gz[query]'.// Compressed file name (keep the original file name, suffix.gz)
            minRatio: 1.// The compression rate is less than 1
            threshold: 10240.// Compress data over 10K
            deleteOriginalAssets: false Set this parameter with care. If you want to provide non-gzip resources, do not set this parameter or set it to false (for example, you can load the original resource file after deleting the packaged gz file).})]}}})}Copy the code