我正在研究Webpack来构建我的模块包 . 我使用文件加载器在javascript中加载图像文件 . 这些行用于加载图像文件:

{
    test: /\.(jpe?g|png|gif|svg)$/i,
    use: [
      {
        loader: 'file-loader',
        options: {
          name: 'images/[name].[ext]'
        }
      },
      'image-webpack-loader'
    ]
  }

但我遇到了麻烦 . 图像路径在css中编译不符合预期 . 我的应用程序有结构:

structure

图像由app / views / index.pug中的 require() 加载:

img(src= require('../images/logo.png'), alt= 'logo')

background-image: url() 在app / styles / style.css中:

.test {
  background-image: url('../images/logo.png');
}

======编译后,build / index.html中的图像路径为:

<img src="images/logo.png" alt="logo">

但build / css / style.css中的图像路径是:

.test {
  background-image: url(images/logo.png);
}

如何检测文件加载器何时在html或css中扫描图像?或者解决这个问题的任何解决方案?

谢谢 .