You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would this be like opening a style tag in .vue single file components?
Yeah. Except I don't want to partition file into sections like Vue does. Keep it JS but add the ability to add CSS styles inside.
Reacted by Andre Wiggins, Gabriel de Oliveira Barbosa, Satyajit Sahoo, Ferran, malinin, Mikhail, Ivan Babak, Maksim Balabash, Yurko Turskiy, happystory and 9 more
Reacted by Daniel Reinoso, Bertrand Marron, danielsarin, Juan David Castro, Nicholas R, Saurabh Sharma, Rohit Gohri, Steven Kitterman, libo, Leon Adler and 1 more
TBH I think astroturf covers all these points, at it's core it's co-locating CSS files in JS. It's actually implemented as that; the tag content is extracted to a CSS file (not written to disk via webpack magic). The really nice thing about this approach is you get ALL the benefits of writing separate files without the work. For instance mini-extraxt-css-plugin and html-plugin both automatically works without any additional setup.
We've got all the relevant standalone loaders, plugins and Babel plugins in repo, you could integrate with a global css tag with all the library details hidden.
We've been using this for all our large projects with Sass and its really hit a nice sweet spot for convenient component API and playing nice with the tons of existing CSS tooling
Reacted by Sunil Pai, Aaron Yodaiken, Jimmy Jia, Chiawen Chen, Yadullah Duman, Math Devie, Pavel Luzanov, Rodrigo, Adam Rose and Remko Tronçon
an astroturf macro would be nice to start playing with this in CRA right now. it appears astroturf has a babel plugin already, so making a macro version shouldn't be too hard?
The macro should be easy enough since the core is a babel-plugin, tho i'm not sure how'd deal we the extracted css files, they'd need to be written to disk somewhere. In a webpack env tho the loader avoids this by using a virtual filesystem plugin, exposes the files only to webpack's fs
@renatoagds astroturf is css-modules, so the behavior is the same, we have :local by default on since that's what css-loader does by default, so all classes are scoped. you can use :global to create global ones instead
Yup – so the contrast here is that astroturf just handles pulling out the CSS into a separate virtual file, without imposing any of its own opinions on how to do CSS processing. It fully uses the existing CSS processing pipeline, which means that if you have Sass set up, then it will run Sass on your styling code – and this is exactly how we use it.
For the part of the API as described above, there's not really any "experience". The whole point is that it doesn't do anything at runtime – it just pulls the CSS out into a separate file, and lets the rest of your pipeline take over.
The experience analogous to defining a CSS module next to my JavaScript, just without having to go bother with having a separate file.
Reacted by Renato Augusto, Pavel Luzanov and Rodrigo
@renatoagds I am using it in production. I use both css and styled function in big React. I converted the project from Emotion.js to astroturf in a few days (mostly because of our auto-import hacks). Animation, many custom PostCSS plugins, webpack CSS minification — everything work. Compare to Emotion we even fix few issues and reduce code size (thanks to &.modifier and @keyframes syntax sugar).
The only problem is that Stylelint doesn’t support it right now. But I created an issue and fix is very simple.
@satya164 yeah for theming custom properties are the best. Not sure how I feel about conditional styles and more complex things. Some use props to define sets of declarations (within a rule) conditionally or do crazy things with them.
@satya164 indeed I would lean towards Linaria (I guess mainly for the composition capabilities).
The only thing I dislike about it is the fact that it uses Stylis for preprocessing. I love Stylis but PostCSS is superior and less flacky. For build time solutions I'd pick PostCSS also because it supports plugins.
FWIW if you only use props/custom properties for theming I wouldn't bother supporting IE11. I would just add a fallback and provide a single default theme (that's how I do at work).
FWIW if you only use props/custom properties for theming I wouldn't bother supporting IE11. I would just add a fallback and provide a single default theme (that's how I do at work).
Some use props to define sets of declarations (within a rule) conditionally.
@giuseppeg can you please explain why this is a bad thing or how it's less efficient? @satya164 what will Linaria do "under the hood" if one attempts to do something like this? Will a class be created for the condition?
@jedmao every time the prop evaluates to a different value the css in js library has to generate a new css rule and inject it in the stylesheet. So even though part of that rule is static (in your example color: black) you end up not reusing it.
And to clarify if you have a highly dynamic application (RTL, theming etc) probably doing these at runtime is way better, my point was that the more you can reuse (compose) the better but of course libraries cache aggressively and for many this is not a big deal!
That color: black declaration, should it be duplicated, would not add any real footprint after gzip, FWIW. But I see your point, if that's indeed how it (Linaria) works under the hood.
I don't see the composition issue though. I've used BEM successfully before with ultimate composition, but I don't think I would lose composition with CSS in JS.
Activity
lucassartori94 commentedon Oct 2, 2018
Would this be like opening a style tag in .vue single file components? I think it'd be a great addition
gaearon commentedon Oct 2, 2018
Also relevant: https://github.com/callstack/linaria
Yeah. Except I don't want to partition file into sections like Vue does. Keep it JS but add the ability to add CSS styles inside.
Timer commentedon Oct 2, 2018
This sounds a bit like
styled-jsx.jquense commentedon Oct 2, 2018
TBH I think astroturf covers all these points, at it's core it's co-locating CSS files in JS. It's actually implemented as that; the tag content is extracted to a CSS file (not written to disk via webpack magic). The really nice thing about this approach is you get ALL the benefits of writing separate files without the work. For instance mini-extraxt-css-plugin and html-plugin both automatically works without any additional setup.
We've got all the relevant standalone loaders, plugins and Babel plugins in repo, you could integrate with a global
csstag with all the library details hidden.We've been using this for all our large projects with Sass and its really hit a nice sweet spot for convenient component API and playing nice with the tons of existing CSS tooling
jquense commentedon Oct 2, 2018
I will say css-modules can be wonky and weird but if you're using them, I think the inline approach is really an ergonomic improvement. Cc @ai too
threepointone commentedon Oct 2, 2018
an
astroturfmacro would be nice to start playing with this in CRA right now. it appears astroturf has a babel plugin already, so making a macro version shouldn't be too hard?kdekooter commentedon Oct 2, 2018
It would be great to treat CSS as a first-class citizen in ReactJS!
ai commentedon Oct 2, 2018
linariais a nice project, but right now I preferastroturf, because of more high order API:styledto created React component like in styled-component.&.primarythen can be used as<Button primary>.styleddeclaration and they still will be scoped.renatoagds commentedon Oct 2, 2018
@jquense just a question, looking at astroturf repo I didn't find that. That's an way to create a local class, like
:localfrom css-modules does?jquense commentedon Oct 2, 2018
@threepointone
The macro should be easy enough since the core is a babel-plugin, tho i'm not sure how'd deal we the extracted css files, they'd need to be written to disk somewhere. In a webpack env tho the loader avoids this by using a virtual filesystem plugin, exposes the files only to webpack's
fs@renatoagds astroturf is css-modules, so the behavior is the same, we have
:localby default on since that's what css-loader does by default, so all classes are scoped. you can use:globalto create global ones insteadtaion commentedon Oct 2, 2018
Yup – so the contrast here is that astroturf just handles pulling out the CSS into a separate virtual file, without imposing any of its own opinions on how to do CSS processing. It fully uses the existing CSS processing pipeline, which means that if you have Sass set up, then it will run Sass on your styling code – and this is exactly how we use it.
renatoagds commentedon Oct 2, 2018
Do we have anyone that use
astroturfin production ? To share the pros and cons using it.taion commentedon Oct 2, 2018
We use astroturf in production right now.
For the part of the API as described above, there's not really any "experience". The whole point is that it doesn't do anything at runtime – it just pulls the CSS out into a separate file, and lets the rest of your pipeline take over.
The experience analogous to defining a CSS module next to my JavaScript, just without having to go bother with having a separate file.
ai commentedon Oct 2, 2018
@renatoagds I am using it in production. I use both
cssandstyledfunction in big React. I converted the project from Emotion.js to astroturf in a few days (mostly because of our auto-import hacks). Animation, many custom PostCSS plugins, webpack CSS minification — everything work. Compare to Emotion we even fix few issues and reduce code size (thanks to&.modifierand@keyframessyntax sugar).The only problem is that Stylelint doesn’t support it right now. But I created an issue and fix is very simple.
59 remaining items
satya164 commentedon Jul 3, 2019
@giuseppeg
Why is that more efficient than CSS variables?
This only lists advantages of Linaria, but it's a start:
astroturfcss/astroturf#69 (comment)
giuseppeg commentedon Jul 3, 2019
@satya164 yeah for theming custom properties are the best. Not sure how I feel about conditional styles and more complex things. Some use props to define sets of declarations (within a rule) conditionally or do crazy things with them.
nhooyr commentedon Jul 3, 2019
I've got a WIP for getting Linaria dynamic props working on IE.
See callstack/linaria#446
giuseppeg commentedon Jul 3, 2019
@satya164 indeed I would lean towards Linaria (I guess mainly for the composition capabilities).
The only thing I dislike about it is the fact that it uses Stylis for preprocessing. I love Stylis but PostCSS is superior and less flacky. For build time solutions I'd pick PostCSS also because it supports plugins.
giuseppeg commentedon Jul 3, 2019
FWIW if you only use props/custom properties for theming I wouldn't bother supporting IE11. I would just add a fallback and provide a single default theme (that's how I do at work).
giuseppeg commentedon Jul 3, 2019
FWIW(2) https://github.com/threepointone/glam tried to implement a polyfill for IE11.
nhooyr commentedon Jul 3, 2019
How would you add a fallback cleanly?
giuseppeg commentedon Jul 3, 2019
with this plugin https://github.com/postcss/postcss-custom-properties
satya164 commentedon Jul 3, 2019
@giuseppeg
It does use stylis by default. But the preprocessor is customizable: https://github.com/callstack/linaria/blob/master/docs/BUNDLERS_INTEGRATION.md#options
jednano commentedon Jul 3, 2019
@giuseppeg can you please explain why this is a bad thing or how it's less efficient? @satya164 what will Linaria do "under the hood" if one attempts to do something like this? Will a class be created for the condition?
There's probably something wrong with my syntax.
To be clear, @satya164, this means you can configure Linaria to use PostCSS as a preprocessor?
giuseppeg commentedon Jul 3, 2019
@jedmao every time the prop evaluates to a different value the css in js library has to generate a new css rule and inject it in the stylesheet. So even though part of that rule is static (in your example
color: black) you end up not reusing it.And to clarify if you have a highly dynamic application (RTL, theming etc) probably doing these at runtime is way better, my point was that the more you can reuse (compose) the better but of course libraries cache aggressively and for many this is not a big deal!
jednano commentedon Jul 3, 2019
That
color: blackdeclaration, should it be duplicated, would not add any real footprint after gzip, FWIW. But I see your point, if that's indeed how it (Linaria) works under the hood.I don't see the composition issue though. I've used BEM successfully before with ultimate composition, but I don't think I would lose composition with CSS in JS.
satya164 commentedon Jul 4, 2019
@jedmao currently Linaria only supports interpolations for property values.
Internally it converts interpolations to CSS variables whose values are updated with the
styleproperty on the component.Yes
jednano commentedon Aug 27, 2019
I just published a craco plugin for Linaria, for those who don't want to eject from CRA, but still want CSS in JS.
darthdeus commentedon May 12, 2020
Is there any news on using astroturf with CRA without ejecting at this point? (other than the above mentioned craco plugin for Linaria)