小编ded*_*bie的帖子

如何使用 webpack-4 解析 sass 文件中的背景图片 URL?

这是我第一次在这里写信,所以请记住这一点。我是第一次在项目中使用 webpack,我遇到了一个问题,我试图在我的 sass 文件中使用背景 url() 函数设置背景图像,如下所示:

.img-container {
  background: url('../../img/homepage-login-prog.jpg') no-repeat center center fixed;
  background-size: cover;
}
Run Code Online (Sandbox Code Playgroud)

我的文件夹结构是:

- css
  | app.css
- dist (this folder is created after building for production)
- img
  | some-image.jpg
- js
  | app.js (entry point for webpack output, 
            this is where I import main.scss file)
- js-vendor
  | vendor.js (third-party libraries like bootstrap, jquery)
- sass  (this is where I keep all my sass files which get compiled using 
         webpack loaders)
  | components …
Run Code Online (Sandbox Code Playgroud)

javascript webpack webpack-style-loader webpack-4

9
推荐指数
3
解决办法
2万
查看次数