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

RFC: CSS extraction #58

Closed
itsdouges opened this issue Jan 20, 2020 · 8 comments · Fixed by #624
Closed

RFC: CSS extraction #58

itsdouges opened this issue Jan 20, 2020 · 8 comments · Fixed by #624
Labels
new feature 🆕 New feature or request rfc 💬 Request for comments

Comments

@itsdouges
Copy link
Collaborator

itsdouges commented Jan 20, 2020

Main point is to do a pass over their own components + node modules dependencies that are using compiled components and then to extract them to a single, atomic, css sheet.

This would need to be a bundler plugin. Webpack & Parcel.

The idea:

  • You have a component library, let's call it @catlaskit
  • You have a product, let's call it Gira
  • Product Gira uses compiled components from @catlaskit
  • Product Gira also defines its own compiled components
  • We'd write this plugin to parse ALL compiled components (from both @catlaskit and Gira, and really anywhere) so when Gira builds their bundle - it extracts ALL compiled components to a CSS file
  • We would want to build it in such a way so if there were cases it would report failures but not fail the build.

Cool right?

@itsdouges itsdouges added the new feature 🆕 New feature or request label Jan 20, 2020
@itsdouges itsdouges pinned this issue Jan 20, 2020
@itsdouges itsdouges unpinned this issue Mar 28, 2020
@itsdouges itsdouges added rfc 💬 Request for comments and removed new feature 🆕 New feature or request labels Apr 6, 2020
@itsdouges itsdouges changed the title Create transformer to "atomic CSS"-ify a consumers styles RFC: Atomic CSS transformer Apr 6, 2020
@itsdouges itsdouges pinned this issue Apr 6, 2020
@itsdouges itsdouges unpinned this issue Apr 10, 2020
@itsdouges itsdouges added this to the v1.0 milestone Apr 11, 2020
@itsdouges itsdouges changed the title RFC: Atomic CSS transformer RFC: Atomic CSS plugin Apr 16, 2020
@itsdouges itsdouges pinned this issue Apr 17, 2020
@itsdouges itsdouges changed the title RFC: Atomic CSS plugin RFC: Atomic CSS bundler plugin Apr 17, 2020
@itsdouges itsdouges changed the title RFC: Atomic CSS bundler plugin RFC: Bundler plungin to extract & atomicify CSS Jun 3, 2020
@itsdouges itsdouges removed this from the v1.0 milestone Aug 2, 2020
@itsdouges itsdouges changed the title RFC: Bundler plungin to extract & atomicify CSS RFC: Bundler plungin to extract CSS Oct 6, 2020
@itsdouges itsdouges added the new feature 🆕 New feature or request label Nov 7, 2020
@itsdouges itsdouges unpinned this issue Nov 9, 2020
@maddhruv maddhruv changed the title RFC: Bundler plungin to extract CSS RFC: Bundler plugin to extract CSS Dec 16, 2020
@itsdouges
Copy link
Collaborator Author

itsdouges commented Jan 3, 2021

I've been doing a spike around the creation of a webpack plugin. Current thoughts:

  • Writing a webpack plugin is harder than I would have liked
  • We can't re-use the AST from the initial Babel run, unfortunately
  • We need to do the file transformation with a webpack loader
  • For simplicity and potential for extension later - we will create a plugin that then patches our extract loader in
  • The loader should be ran after the initial babel run
  • MVP of the plugin will not support HMR or anything of the like - with the assumption that the plugin only runs in PROD
  • By default it should target every JS file - with config to constrain it to specific packages/files via the usual glob/regex approach common in webpack loaders

@cometkim
Copy link

cometkim commented Jan 3, 2021

@Madou would this be an option?

It would be nice to have additional options. However, there may be users who don't want the default behavior to change.

@itsdouges
Copy link
Collaborator Author

what option are we talking about?

@cometkim
Copy link

cometkim commented Jan 3, 2021

I'm wondering if it'll be necessary to extract CSS using the bundler plugin

Or can users keep using this library without the css extraction?.


Context:

I know extracted CSS works more efficiently in the browser, but in some cases is not, such as code--splitting and streaming. (And I think this is one of the main reasons Atomic CSS become necessary)

However, most of "(Near) Zero-runtime" CSS libs supports only pre-extracted ones but it has less advantages in React apps.

@itsdouges
Copy link
Collaborator Author

itsdouges commented Jan 3, 2021

ah okay

you can keep using the library without CSS extraction 👍 - my advice is if you're publishing a design system or component library to NPM - don't extract to CSS yet

in an app that is consuming the design system, or component library, or even just writing their own components - turn on the CSS extraction so you get great performance gains, but still having the same developer experience and behaviour you're used to when writing CSS-in-JS

it is purely an additive thing however - again completely optional.

@itsdouges itsdouges changed the title RFC: Bundler plugin to extract CSS RFC: CSS extraction Feb 2, 2021
@cloudkite
Copy link

Excited about this library, nice work 🎉

In terms of code-splitting and SSR, will this support exporting to multiple CSS files that get loaded alongside their relevant async js chunk? I'm thinking about scenarios like nextjs.

@itsdouges
Copy link
Collaborator Author

itsdouges commented Feb 10, 2021

Hi @cloudkite,

Currently it's planned to only extract to a single, atomic CSS file, with a critical CSS api available for initial SSR. The need for CSS chunks might not be needed - but it's something we're open to evaluate down the track 😄.

@itsdouges
Copy link
Collaborator Author

Current spike #561 and good discussion here #575

@itsdouges itsdouges mentioned this issue Mar 10, 2021
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature 🆕 New feature or request rfc 💬 Request for comments
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants