简体   繁体   English

Webpack 不处理 CSS 背景图像

[英]Webpack doesn't process CSS background image

The following Webpack configuration does not allow me to process CSS images as the background property:以下Webpack 配置不允许我将 CSS 图像处理为背景属性:

background: url('./hero.jpg') no-repeat right;

results in the following error:导致以下错误:

ERROR in ./src/app/components/Contact/Contact.style.scss (./node_modules/mini-css-extract-plugin/dist/loader.js??ruleSet[1].rules[1].use[1]!./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/app/components/Contact/Contact.style.scss)
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/css-loader/dist/cjs.js):
Error: Can't resolve 'assets/img/section/hero.jpg' in 

What URL should I pass ass the CSS property so that Webpack would catch it?我应该通过什么 URL 来传递 CSS 属性,以便 Webpack 能够抓住它?

Dist directory screenshot: Dist 目录截图:

距离

Public directory screenshot:公共目录截图:

上市

Resolved myself.自己解决了。 Please reach for helping with the solution:请联系以寻求解决方案的帮助:

{
  test: /\.(png|jpg|gif)$/,
  loader: 'file-loader',
  options: {
    publicPath: path.resolve(__dirname, '/assets/img'),
    outputPath: 'assets/img',
    name: '[name].[ext]'
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM