-
-
Notifications
You must be signed in to change notification settings - Fork 387
extract mediaquery feature #162
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
Comments
@SassNinja idea is good, i think it is possible solve using Idea: we should slit our build chunk on chunk contains only media queries and then extract from this chunk css. I would help with this, but at the moment there is no time. Maybe perhaps we need more and we can send PR to Any splitting should be done in |
Interesting idea @evilebottnawi but I'm afraid According to the docs you can define a pattern which modules belong to a specific cacheGroup. But I don't see a possibility to treat the This doesn't work: optimization: {
splitChunks: {
cacheGroups: {
tablet: {
test: /@media/,
chunks: 'all',
name: 'tablet'
}
}
}
} Were you talking about this or did you have something else in mind? |
@SassNinja inside bundle all in |
Looks like we already do something for |
Example: .foo { color: blue; }
@media screen and (max-width: 40em) {
.foo { color: red; }
}
.bar { font-size: 1rem; }
@media screen and (max-width: 40em) {
.bar { font-size: 2rem; }
}
.test { z-index: 1; } Should be modify to @import url('example-tablet.css') screen and (max-width: 40em);
.foo { color: blue; }
.bar { font-size: 1rem; }
.test { z-index: 1; } Need tests, i just write this based on looking logic. If my example works. We can implement this using |
Plugin already exists https://github.com/Ghostavio/postcss-extract-media, maybe need rewrite |
Main problem what css is not module language and it is hard to solve this using bundle algorithms |
@evilebottnawi nice finding 👍 But I have to ask
What exactly do you mean?
Yup probably needs a major rewrite. Seems to me it's meant to be used with grunt or gulp. |
@SassNinja we need split our one css on multiple css - main contain css code other based on media, feel free to experiments and ask question |
@evilebottnawi I've now the impression it's impossible with webpack itself (or rather splitChunks) due to the way it handles chunks. Your example with After digging again into the postcss-extract-media plugin I think the only way is to split and emit the file within the postcss plugin. |
@SassNinja yep, |
Some time has passed and I've got now a working plugin for the extraction
So would it be ok if I adjust the README of this repo and add a section about using my plugin together with the mini-css-extract-plugin? Or did I get you wrong? |
@SassNinja PR welcome, please add example too |
In the course of a meeting with Google I've got the recommendation to split the CSS by media queries into separate files.
I'm trying to find a webpack solution to this for some days but without any success so far.
I've found postcss plugins such as css-mqpacker or webpack plugins such as css-magic-split-webpack-plugin. But none of them seem to be a real solution.
The goal is that webpack transforms the following code
example.css
into
example.css
example-tablet.css (or any other name)
@evilebottnawi is this something that belong to the mini-css-extract-plugin or would you rather see it as a new plugin?
The text was updated successfully, but these errors were encountered: