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

声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。
随机推荐
CSS 基本语法
CSRF 双重 Cookie 验证
Node.js http 模块
WordPress 使用 shortcode() 增加编辑器功能
JavaScript 类操作 classList
WordPress 添加 Favicon 图标的方法
冒泡法排序
Windows 服务命令 sc