您好,欢迎来到意榕旅游网。
搜索
您的当前位置:首页VUE配置compression-webpack-plugin打包压缩js,css

VUE配置compression-webpack-plugin打包压缩js,css

来源:意榕旅游网
VUE配置compression-webpack-plugin打包压缩js,css

1.安装compression-webpack-plugin

npm install --save-dev compression-webpack-plugin

2.vue.config.js配置

const CompressionPlugin = require(\"compression-webpack-plugin\");

const IS_PROD =[\"production\

module.exports = {

chainWebpack: (config) => { // 开启js、css压缩 if (IS_PROD) {

config.plugin(\"compressionPlugin\").use( new CompressionPlugin({

test: /\\.js$|\\.html$|\\.css/, // 匹配⽂件名 threshold: 10240, // 对超过10k的数据压缩 deleteOriginalAssets: false, // 不删除源⽂件 }) ); } }}

3.run build 报错

ERROR TypeError: Cannot read property 'tapPromise' of undefinedTypeError: Cannot read property 'tapPromise' of undefined

排查原因是版本太⾼。执⾏以下命令

npm uninstall compression-webpack-pluginnpm i compression-webpack-plugin@5.0.1

PS:我在另⼀个项⽬配置,报出了其他错误,排查原因是webpack版本的问题,卸载当前webpack版本 安装4.0.0版本解决

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- yrrf.cn 版权所有 赣ICP备2024042794号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务