Skip to content
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

Absolute paths #15

Closed
wants to merge 2 commits into from
Closed

Absolute paths #15

wants to merge 2 commits into from

Conversation

mightyaleksey
Copy link
Member

I think we should provide real paths using config.from. Will be easier to use CSS Modules core plugins together with the other postcss plugins.

Also loader-core should be updated.

@geelen
Copy link
Member

geelen commented Sep 19, 2015

Hey @sullenor, sorry I haven't looked at this PR yet. I've just had a look through the diff here and on css-modules/css-modules-loader-core#25

So the bug is to do with importing from files inside node_modules? Or is specifically to do with postcss-url? Trying to figure out why this needs to have breaking changes to this module....

@mightyaleksey
Copy link
Member Author

In beginning, I found that problem, when I tried to work with postcss-url plugin. Basically, the problem comes from the way the css-loader uses postcss plugin's API.

The css-loader creates a single pipeline for each processing file and provides file content and file path to it. File path affects the source property of nodes in the result CSS tree which is used by plugins. I found out that css-loader provides short paths to the pipeline: https://github.com/css-modules/css-modules-loader-core/blob/master/src/index.js#L17 which are not relevant to the original file. So the plugins which use provided file path to resolve paths in the code don't work. Also it may result in generating wrong source maps.

I decided to fix it by providing relevant paths here: https://github.com/css-modules/css-modules-loader-core/blob/master/src/index.js#L17
Also, those paths were used by the scope plugin to generate class names. So I tried to keep them short only in the scope plugin.

@mightyaleksey
Copy link
Member Author

Also, I made a quick solution as another postcss plugin which fixes paths: https://github.com/sullenor/todos/blob/master/postcss-fix-paths.js
It is a small hack, but it works :)
You can see the usage in the todos project: https://github.com/sullenor/todos/blob/master/gulpfile.babel.js#L22-L41

I use it load icons from the font-awesome package

@TrySound TrySound closed this Jun 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants