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

Optional insertion point? #14

Closed
madeleineostoja opened this issue May 18, 2017 · 5 comments
Closed

Optional insertion point? #14

madeleineostoja opened this issue May 18, 2017 · 5 comments
Labels

Comments

@madeleineostoja
Copy link

madeleineostoja commented May 18, 2017

First of all whoa, love what you've done with this plugin @jonathantneal!

What do you think about providing an optional insertion point hook for the Normalize styles? It's common for buildsteps to operate on multiple CSS files and since postcss-normalize blindly injects into everything it finds you could easily end up with duplicated code without realising, which defeats the purpose of saving bytes with browserlist. This is especially true of more complex SPAs and the like.

Of course you can mitigate this with a dedicated buildstep just for postcss-normalize, but it seems like a gotcha for users.

Maybe something like

/* Inject browserlisted Normalize here */
@normalize

.rest-of-my-rules {
  ...
}
require('postcss-normalize').process(YOUR_CSS, {
  atRule: true
});

Then if it doesn't find the @normalize rule in a given document it doesn't inject anything. Also gives this method with the current standard of importing Normalize.css with postcss-import, ie:

/* Inject Normalize here */
@import 'normalize.css'


.rest-of-my-rules {
  ...
}
@jonathantneal
Copy link
Collaborator

I think this is a great idea. I’d love to know what others think. I wonder if there’s another injection pattern we can borrow. I like your idea. I just want to give others a chance to show us an even better way, if one exists.

@ben-eb
Copy link

ben-eb commented May 19, 2017

https://github.com/postcss/postcss-plugin-context would do that.

@madeleineostoja
Copy link
Author

Ah perfect thanks @ben-eb

Maybe we should just mention that pattern in the readme? Common enough use-case IMO.

@jonathantneal
Copy link
Collaborator

This is now possible!

@import "postcss-normalize";

@madeleineostoja
Copy link
Author

Nice! So just to clarify - if a given CSS file/input doesn't have an import statement, postcss-normalize won't get injected at all? Because from the docs sounds like this just controls the injection point within the same bundle/CSS file.

If that's the case, I still think it would need an optional Boolean to only use the injection point. Or as ben-eb pointed out, just document using postcss-plugin-context (using that pattern on simpla.io and works a treat).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants