多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# webpack打包生成gz文件 安装插件(compression-webpack-plugin): ```bash npm install compression-webpack-plugin --save-dev ``` ### vue.config.js文件进行webpack配置: ```javascript const CompressionPlugin = require('compression-webpack-plugin'); module.exports = { plugins: \[ new CompressionPlugin({ algorithm: 'gzip', // 使用gzip压缩 test: /\\.js$|\\.html$|\\.css$/, // 匹配文件名 filename: '\[path\].gz\[query\]', // 压缩后的文件名(保持原文件名,后缀加.gz) minRatio: 1, // 压缩率小于1才会压缩 threshold: 10240, // 对超过10k的数据压缩 deleteOriginalAssets: false, // 是否删除未压缩的源文件,谨慎设置,如果希望提供非gzip的资源,可不设置或者设置为false(比如删除打包后的gz后还可以加载到原始资源文件) }), \], } ``` ### nginx.conf: ```bash http { include mime.types; default\_type application/octet-stream; sendfile on; #tcp\_nopush on; #keepalive\_timeout 0; keepalive\_timeout 65; gzip\_static on; server { listen 8462; server\_name localhost; location / { root dist; index index.html index.htm; } error\_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } ```