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

声明:本站所有文章和图片,如无特殊说明,均为原创发布。商业转载请联系作者获得授权,非商业转载请注明出处。
真诚赞赏,手留余香
赞赏
随机推荐
CRSF 跨站脚本攻击已死,使用 Same-Site Cookies 来防范 CSRF
JavaScript 和 CSS 检测横屏适配
Debian11 安装笔记4:安装常用软件
JavaScript 中 0.1 加 0.2 不等于 0.3 的原因和解决方法
什么是 RESTful API 的幂等性
WordPress 常用函数 / sanitize_user
Linux 网络流量监控 iftop
WordPress 文章排序