Webpack file-loader 升级后 src= "[object Module]" 的解决方法

Webpack file-loader 升级后 src= "[object Module]" 的解决方法,当 file-loader 的版本是 4.3.0 及以上,则需要在 webpack.config.js 中手动配置属性 esModule 。


{
  test: /\.(jpg|jpeg|png|gif|svg)$/,
  loader: "file-loader",
  options: {
    esModule: false, // 默认值是 true,需要手动改成 false
  }
}




esModule

Type: Boolean Default: true

By default, file-loader generates JS modules that use the ES modules syntax. There are some cases in which using ES modules is beneficial, like in the case of module concatenation and tree shaking.


You can enable a CommonJS module syntax using:


webpack.config.js

module.exports = {
 module: {
  rules: [
   {
    test: /\.css$/,
    use: [
     {
      loader: 'file-loader',
      options: {
       esModule: false,
      },
     },
    ],
   },
  ],
 },
};





参考:

https://webpack.js.org/loaders/file-loader/#esmodule

声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。
随机推荐
JavaScript DOM 查找元素
HTML 弹跳式的滚动一行文字
Express 使用 cookie-session 处理 session
github Support for password authentication was removed
Nine 主题
Git 放弃本地修改,强制和之前的某次提交同步
Land APP 小程序
FormData 对象