Webpack - sass loader cannot find images

前端 未结 3 1147
误落风尘
误落风尘 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:04

    You can use ignore-loader if your images are already in the place where you need them. file-loader will copy the files to your output folder.

    0 讨论(0)
  • 2020-12-17 10:13

    To solve this problem I've uploaded this webpack extremly basic configuration to start my projects, I hope it can help everyone who had this problem. Suggestions are all welcome of course.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题