[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
使用vue-cli3搭建的vue 项目是没有
productionGZip配置的,需要你安装插件compression-webpack-plugin并在vue.config.js中进行相应的配置才能实现项目的性能优化
<>1、安装插件:compression-webpack-plugin
npm i -D compression-webpack-plugin
<>2、在 vue.config.js 文件中配置 compression-webpack-plugin
const compressionWebpackPlugin = require('compression-webpack-plugin'); //引入插件
const productionGZipExtensions = ['js', 'css']; //压缩的文件类型 module.exports = {
//简单配置 configureWebpack: { plugins: [ new compressionWebpackPlugin({ //[file]
会被替换成原始资源。[path] 会被替换成原始资源的路径, [query] 会被替换成查询字符串。默认值是 "[path].gz[query]"。 asset
: '[path].gz[query]', // 提示[email protected]的话asset改为filename
//可以是 function(buf, callback) 或者字符串。对于字符串来说依照 zlib 的算法(或者 zopfli 的算法)。默认值是
"gzip"。 algorithm: 'gzip', //所有匹配该正则的资源都会被处理。默认值是全部资源。 test: new RegExp('\\.(' +
productionGzipExtensions.join('|') + ')$'), //只有大小大于该值的资源会被处理。单位是 bytes。默认值是 0。
threshold: 10240, //只有压缩率小于这个值的资源才会被处理。默认值是 0.8。 minRatio: 0.8 }) ] }, //复杂配置
/*configureWebpack: config => { if(process.env.NOVE_ENV === 'production'){
config.push( new compressionWebpackPlugin({ asset: '[path].gz[query]', //
提示[email protected]的话asset改为filename algorithm: 'gzip', test:
new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'), threshold:
10240, minRatio: 0.8 }) ) } }else{} */ }
<>3、使用 compression-webpack-plugin 后打包项目过程中报错的解决方式:
① 如果 [email protected] 的话,就把 vue.config.js 中关于
compression-webpack-plugin 配置 asset 改为 filename ② 如果构建过程中提示一些属性找不到,那么可以把项目中的
package.lock.json 和 node_modules 删除, 并把 package.json 中关于
compression-webpack-plugin 版本调低,如:1.1.12,然后重新 npm install 和 npm run build