web发布JS压缩

1、安装插件compression-webpack-plugin

yarn add compression-webpack-plugin

2、配置vue.config.js

// 压缩css、js
const CompressionWebpackPlugin = require('compression-webpack-plugin');
// 要压缩的文件
const productionGzipExtensions = ['js', 'css'];

configureWebpack: (config) => {
    if (env !== 'development' || env !== 'test') {
        config.plugins.push(new CompressionWebpackPlugin({
            algorithm: 'gzip',
            test: new RegExp(`\\.(${productionGzipExtensions.join('|')})$`),
            threshold: 10240,
            minRatio: 0.8,
        }));
    }
}

你可能感兴趣的:(web发布JS压缩)