Skip to content

Rewrite @import and url() resolution as PostCSS plugins #558

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

Closed
andyjansson opened this issue Jun 21, 2017 · 7 comments
Closed

Rewrite @import and url() resolution as PostCSS plugins #558

andyjansson opened this issue Jun 21, 2017 · 7 comments

Comments

@andyjansson
Copy link

andyjansson commented Jun 21, 2017

I'm a member of the cssnano team. Due to the way css-loader works, we've had to make certain allowances to the code in order to keep everything functioning correctly [1][2]. Unfortunately, as the code keep on evolving, we continue running into issues which has to do with the integration in css-loader. Rather than continuing the trend of implementing hacks in individual packages, we'd rather fix the issue at its source.

Upon reviewing css-loader's code base, we learned that cssnano is included in a postcss pipeline preceded by a local plugin called css-loader-parser which replaces @import and url() references with ___CSS_LOADER_ constants. This causes some issues for us because at the time the CSS AST reaches cssnano, the CSS is still unfinished and is actually finalised using regex replacement after the pipeline has finished. Not only is this problematic for us, but it may also cause issues when control is returned back to webpack due to the CSS (having been minified and optimised) no longer is what css-loader expects (which is seemingly also why css-loader excludes certain optimisations). Rather than working on unfinished CSS and leaving users with a diminished experience, we feel that cssnano should be invoked at the very end, working with the fully processed CSS.

After some discussion between me and @ben-eb, we concluded that the ideal course of action would be to remove the regex replacements and instead replace them with postcss plugins, allowing all processing to be done within the pipeline. This would not only solve the issues for us, but would probably also make css-loader a bit more performant and manageable as well.

We'd love to hear your thoughts on this.

@TrySound
Copy link
Contributor

Yo, guys! Did you read sokra's icss2 proposal?
https://medium.com/webpack/the-new-css-workflow-step-1-79583bd107d7
I started implement it in postcss-icss-import and postcss-icss-url
I almost done with fixing values (last one) plugin. Next step is finishing new-loader

@TrySound
Copy link
Contributor

Do you think this example will be processed correctly?

.foo {
  background: url(__url__0);
}

@andyjansson
Copy link
Author

@TrySound 👋

I read through the proposal. I don't think there's enough detail to say how we're going to be affected by it. We'd just like to be fed fully formed CSS and not have to bother with how webpack handles things internally. Also, what's the time frame for this thing?

@TrySound
Copy link
Contributor

New-loader will process only icss which is only :import and :export rules. All other things will be processed with postcss-loader and icss (css-modules) plugins.

@TrySound
Copy link
Contributor

I'm gonna care about css-loader this week.

@andyjansson
Copy link
Author

@TrySound any update on this?

@michael-ciniawsky
Copy link
Member

#655

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

No branches or pull requests

3 participants