webpack5踩坑记录

151 阅读1分钟

webpack5配置图片使用generator属性时报错(vue2)

各种版本

node 14
webpack 5.90.3
webpcak-cli 5.1.4
webpack-dev-server 4.15.1

问题表现

module: {
    rules: [
      {
        // webpack已经内置file-loader url-loader不需要引入直接配置
        // https://www.webpackjs.com/guides/asset-modules/
        test: /\.(png|jpg|jpeg|gif)$/,
        type: "asset", 
        generator: {
          filename: "static/imgs/[hash:8][ext][query]",
        }
      }
    ]
  },

image.png

解决方案:

将vue-loader升级或者降级到15.11.1