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

声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。
随机推荐
WordPress 使用 shortcode() 增加编辑器功能
JavaScript ES6 模块
版权相关
MySQL 数据库中货币单位如何存储
URLSearchParams 对象
在 HTML 中引入 CSS
JavaScript Map 详解
WordPress 函数 add_option()、get_option() 和 update_option()