reworkcss / rework-npm

Import CSS from npm modules using rework
BSD 2-Clause "Simplified" License
87 stars 19 forks source link

Rewrite relative url paths #16

Closed necolas closed 10 years ago

necolas commented 10 years ago

This is probably over-simplified, but something like this…

components/a.css:

.a { background: url("a.png"); }

components/b.css:

.b { background: url("b.png"); }

both.css:

@import "components/a.css";
@import "components/b.css";

output (desired):

.a { background: url("components/a.png"); }
.b { background: url("components/b.png"); }
conradz commented 10 years ago

When would this be useful? In rework-assets I used the position.source property on the node to find where the file is. Rewriting the URL paths would make them not relative to the position.source file.

necolas commented 10 years ago

I was looking at what https://github.com/bem/borschik does. But I see in rework-assets:

This means that even if the source document is parsed from several files (for example when using rework-npm), it will still resolve the referenced asset using the source file path.

So I guess this works as long as you stay within rework-land.

Thanks

conradz commented 10 years ago

It would be pretty easy to write a plugin to resolve the URLs using position.source and then rewrite them relative to another directory.