vue cli3/vue cli4开启gzip打包报错:TypeError: Cannot read property 'tapPromise' of undefined

给我的项目增加gzip打包,vue cli版本是4.5.0,结果报以下错误:

1、首先:yarn add compression-webpack-plugin -D(给我安装的是7.1.0

vue cli3/vue cli4开启gzip打包报错:TypeError: Cannot read property 'tapPromise' of undefined

2、然后修改vue.config.js

const CompressionWebpackPlugin = require('compression-webpack-plugin');
  configureWebpack: {
    plugins: [
      new CompressionWebpackPlugin({
        filename: '[path].gz[query]',
        algorithm: 'gzip',
        test: /\.(js|css)(\?.*)?$/i,
        threshold: 10240, // 对超过10k的数据进行压缩
        minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
        deleteOriginalAssets: false, // 删除原文件
      }),
    ],
  },

3、最后执行npm run build

4、然后出错……

TypeError: Cannot read property 'tapPromise' of undefined

vue cli3/vue cli4开启gzip打包报错:TypeError: Cannot read property 'tapPromise' of undefined

第一反应是删除node_modules包重新安装,然并卵

然后我安装5.0.0就解决了这个问题

vue cli3/vue cli4开启gzip打包报错:TypeError: Cannot read property 'tapPromise' of undefined

vue cli3/vue cli4开启gzip打包报错:TypeError: Cannot read property 'tapPromise' of undefined

上一篇:基于SSL(TLS)的HTTPS网页下载——如何编写健壮的可靠的网页下载


下一篇:Nginx服务器的Gzip压缩