-
-
Notifications
You must be signed in to change notification settings - Fork 609
CSS modules break build if used with ~
#589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@jantimon why don't use |
@evilebottnawi this won't work if I am looking for a syntax which can be used with different css-loader configs for my plugin |
For now I am working around this issue by forcing the user to tell me wether he is using cssModules or not: https://github.com/jantimon/iconfont-webpack-plugin/blob/master/example/module/webpack.config.js#L30 |
Is this considered an inconsistency? I wish I could fix this. |
Yes, it definitely is. I believe this also may be the cause of some confusion in issues like #12. |
Seems bug PR welcome! |
Just information: I had the same issue, it seems kinda counterintuitive: :global { * { background: url('~assets/my-asset.svg'); } } // works :local { * { background: url('~assets/my-asset.svg'); } } // does not work :local { * { background: url('assets/my-asset.svg'); } } // no tilde here but works That is odd behaviour. Because of this resolving the actual URL is context-sensitive making global variables ala bootstrap-sass (e.g. |
I find the reason: https://github.com/webpack-contrib/css-loader/blob/master/lib/processCss.js#L163-L174 :local { * { background: url('~assets/my-asset.svg'); } }
// urlToRequest
:local { * { background: url(require('~assets/my-asset.svg')); } } else the mode is 'global', url will recognize the :global { * { background: url('~assets/my-asset.svg'); } }
// urlToRequest
:global { * { background: url(require('assets/my-asset.svg')); } } |
Using vue-loader which allows modules to be turned on or off per <style> tag. Using or omitting a tilde in the font paths breaks my code in different places, as fonts no longer resolve depending on the module tag. Toying with possible build-process workarounds. Wish I had the background to fix it right. |
This problem still exists. |
@evilebottnawi could you please summarize how this issue was solved? |
@jantimon we use same logic for resolving urls with |
You can try master branch, feel free to feedback |
@evilebottnawi |
Please use latest version of |
What is the current behavior?
Using a tilde
~
inside a css file causesCan't resolve '~'
if css-modules feature is activated:If the current behavior is a bug, please provide the steps to reproduce.
The bug can be reproduced this way: (https://github.com/jantimon/css-loader-bug)
git clone https://github.com/jantimon/css-loader-bug.git cd css-loader-bug npm install npm run without-modules npm run with-modules
Working webpack.config.js
Broken webpack.config.js
CSS File
What is the expected behavior?
Compilation should work even if
modules
are set to true.Motivation
I wrote a loader which adds
~!!
to a css file and it does not know if the user is using css-modules: https://github.com/jantimon/iconfont-webpack-plugin/blob/master/lib/postcss-plugin.js#L135-L137The text was updated successfully, but these errors were encountered: