Webpack - sass loader cannot find images

前端 未结 3 1157
误落风尘
误落风尘 2020-12-17 09:54

The sass loader doc says: \"If you\'re just generating CSS without passing it to the css-loader, it must be relative to your web root\". So i did a

3条回答
  •  被撕碎了的回忆
    2020-12-17 10:17

    As far as I can see you are actually using the css loader ( "style", "css", "sass", "resolve-url" ) (the "css" part is the "css-loader")

    In your sass file(s) you should link to the images using a relative path from the sass file you are editing.

    styles
     - somefile.scss
     - another.scss
    images
     - someImage.jpg
    

    in somefile.scss, you should link to your image like this:

    background-image: url("../images/someImage.jpg);

    Do note, that if you want webpack to move those images to your distribution folder (if you are using a system like this) that you will need something like file-loader to copy those files over.

提交回复
热议问题