Repository navigation
Use stylis instead of PostCSS (21kB -> 9kB 🎉) - #286
Conversation
Package size (min+gzip) with... - PostCSS: 21kB - stylis: 9kB :tada: I hack around stylis model a bit, because we e.g. don't want to prefix keyframes with the generated classname. (something stylis does by default). Maybe @thysultan can chime in here if there's any chance we could change this, otherwise this (slightly ugly) works too! This isn't done as we need to do dependency cleanup and fix the whitespace changes in the tests, but I wanted to kick off a first discussion! /cc @geelen
|
I've updates stylis. You can now opt out of namespacing keyframes & animations, more details on the readme |
Generated by 🚫 dangerJS |
|
Most of the test failures are whitespace related, but there's two actual regressions when using stylis:
/* The above should generate this CSS.. */
.somerandomhash { }
.somerandomhash > h1 {
color: red;
}
/* ...but generates this 😢 */
.somerandomhash { }
> h1 {
color: red;
}
|
|
I am using the caniuse-api to fetch browser versions and prefix support. I might not have all prefixes, but https://github.com/rofrischmann/inline-style-prefixer/blob/master/generator/searchMap.js shows pretty much all properties I am checking. The key represents the caniuse search name. Also by default I am only prefixing properties for "modern" browsers (see https://github.com/rofrischmann/inline-style-prefixer#browser-support):
That means it won't prefix e.g. |
|
@mxstbr stylis has gone through some updates so it now supports everything listed in css-we-support.md and more. |
|
Awesome!! Will update this PR soon – we'll release it as v2.0.0 (i.e. a breaking change to make sure people don't kill us) in January, together with #227! |
|
So this needs some work before it can proceed—converting objects isn't quite working right (see the failing tests). Can you take a look @mxstbr? |
While v0.9 of stylis is out, it introduces features we really really don't want to have. (Sass-style `@mixin`, variables with `~~var`) I've upgraded to 0.8, which is the last version that has bugfixes we need but no unnecessary features. See the changelog here: https://github.com/thysultan/stylis.js/blob/master/CHANGELOG.md /cc @thysultan @geelen
|
While v0.9 of stylis is out, it introduces features we really really don't want to have. (Sass-style |
|
Let's go with 3. then? Would that be a big effort? |
|
@mxstbr no it's not, will push a patch later today. |
|
Now I'm getting duplicates: // I get (notice the double .d)
.sc-a { } .c { color: blue; } .c > h1 { font-size: 4rem; } .sc-b { } .d { color: blue; } .d > h1 { font-size: 4rem; } .d { color: red; }
// I want
.sc-a { } .c { color: blue; } .c > h1 { font-size: 4rem; } .sc-b { } .d { color: blue; color: red; } .d > h1 { font-size: 4rem; } Intended? |
|
@mxstbr what is the input? |
color: blue;
> h1 { font-size: 4rem; }
color: red; |
|
@mxstbr Yes that's intend, this is the method that preserves the order in which they are declared to avoid css specificity issues... if it where They would be together, anything that is not also flat css will break the current context of flat css and append that, when flat css is encountered again a new flat css context is initiated. |
|
@thysultan you shouldn't (I don't think) have any specificity issues grouping all rules at the same level together. As long as the order within each CSS rule is preserved, you should be fine to pull That said, what you're currently outputting will work fine too. It just might look a little weirder in devtools. |
|
@geelen edge case: color: red;
& {
color: blue;
}
color: orange;
Maybe PostCSS and Sass will group them all under one selector? |
Though if that's the case then multiple selectors might break it. color: red;
&, h1 {
color: blue;
}
color: orange; |
|
In your first case, Sass outputs this: // Input
color: red;
& {
color: blue;
}
color: orange;
// Output
div {
color: red;
color: orange;
}
div {
color: blue;
}So yeah, that breaks it. That behaviour might even be more consistent than Sass? |
Awesome, will update the PR! |
|
As soon as CI passes this is ready to go! 🎉 |
|
Failed because of CHANGELOG entry, but we'll have to do that for v2 down the line anyway. SHIPPING! |
|
Just wanted to thank you @thysultan. You did amazing work! 💯 |
|
I have massive change when updating a project from v1.4.3 to v2.0.0-4, I suspect this is because of this. I have no experience with stylis, and I've learned postcss when I started to use styled-components. I have now a whole module for making website like bootstrap that require a old version of styled components. Did I miss the discussion of postcss >< stylis ? What are the big change and what about retro compatibility ? |
|
How do you mean massive change @kopax, is everything broken? |
|
@mxstbr, the last semicolon of rules break the css. That can be corrected by it requires some cold blood and redbull, apparently if styled-component release a By massive I meant that media query issues described in #453 (see http://www.webpackbin.com/4J0u-y_Ff) have a major bug which break massively our stylesheets with ignored css from theses broken components. |
Will do that now! |


styled-components bundle size (min+gzip) with...
I hack around stylis API a bit, because we e.g. don't want to prefix keyframes with the generated classname. (something stylis does by default). Maybe @thysultan can chime in here if there's any chance we could change this, otherwise this (slightly ugly) works too!
This isn't done as we need to do dependency cleanup and fix the whitespace changes in the tests, but I wanted to kick off a discussion if we want to go down that route!
cc @geelen