A
A
Anubis2018-05-09 11:22:18
css
Anubis, 2018-05-09 11:22:18

How to make friends css-loader with modules: true and import url in style files?

The error reproduces the same with less-loader and postcss-loader. If I include modules: true in the css-loader options, then the collector does not see the content of relative url(...) in style files. background: url('kitty.jpg') and url('./kitty.jpg') throw an error:

Module not found: Error: Can't resolve 'kitty.jpg' in '/Users/anubis/Projects/Kooler/src/client/engine/components'

But if you specify url('../components/kitty.jpg'), that is, first go to the next level, then return to the folder and specify the file, everything works. Import also works if you add a backslash at the beginning: url('\./kitty.jpg') I don't want to hang such crutches throughout the project, but I don't want to give up the convenient css modules feature either.
I have not been able to google the solution yet, maybe one of my colleagues has already encountered the situation and will be able to suggest a solution.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anubis, 2018-05-09
@Anubis

What worked for me was adding resolve-url-loader before postcss-loader/less-loader

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question