Media queries support & 1.0 release #18
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
About a month ago I was chatting with Mark & Josh about what's needed for a full 1.0 release of CSS Modules. I argued that we needed a first-class method for importing media queries, which I've been thinking about since and implemented over the last couple of weeks.
Here's my proposal:
@custom-media
spec@custom-media
statements are exported@custom-media --breakpoint from "./file.css"
For example:
Now, in order for this to occur, I've had to add the postcss-custom-media plugin to run after the import statements are linked but before the
injectableSource
is ready to hit the browser. That's because custom media needs a polyfill, which needs to run before the CSS is usable. So the@custom-media
expressions are processed & removed before they hit the browser. That means they don't have to be localised like class names do.However, I am not 100% sure about this design.
@custom-media
will eventually be available in the browsers, and so then we'd need to change behaviour to localise media expressions. There'd also not be any point in importing@custom-media --breakpoint from "file.css", something like
@media (--breakpoint from "file.css")` would make much more sense. That syntax breaks Sass, which is why I haven't used it yet. But it's a thought.An alternative is coming up with a totally general variable export/import syntax (probably building on postcss-simple-vars) that could be used for media queries as well.
Anyway, wanted to open the discussion. I've pushed the postcss transforms used here to npm under the
beta
tag, so this build should be passing (travis is having weird problems with Node v0.10 and v0.12 today, but IO v3 is building fine).I'd love to have this merged and v1 released by the time I present CSS Modules at React Rally on the 24th.