美文网首页VUE相关文章
vue-cli3 配置 gzip 压缩

vue-cli3 配置 gzip 压缩

作者: karl_song | 来源:发表于2019-07-20 16:26 被阅读0次

    vue-cli3 配置 gzip 压缩

    vue.config.js 配置

    <!--gzip 压缩-->
    const CompressionWebpackPlugin = require("compression-webpack-plugin");
    const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
    
    module.exports = {
        configureWebpack: config => {
            const plugins = [];
    
            // Begin 生成 gzip 压缩文件
            plugins.push(
                new CompressionWebpackPlugin({
                    filename: "[path].gz[query]",
                    algorithm: "gzip",
                    test: productionGzipExtensions,
                    threshold: 10240,
                    minRatio: 0.8
                })
            );
            // End 生成 gzip 压缩文件
            
            config.plugins = [...config.plugins, ...plugins];
        }
    }
    
    

    nginx.conf 配置

    gzip_static on; # 开启 gzip 压缩
    

    如果服务器配置未生效,可参考下文设置:

    https://juejin.im/post/5bf422a46fb9a049dd7fe668

    https://segmentfault.com/q/1010000010184927/a-1020000010194441

    相关文章

      网友评论

        本文标题:vue-cli3 配置 gzip 压缩

        本文链接:https://www.haomeiwen.com/subject/khsulctx.html