feat: Using CSS data urls for bundling #513
Draft
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.
Resolving #297
Idea
The idea is that the Babel plugin should be able to generate import statements that import CSS as data URLs. After this, bundlers should be able to generate CSS bundles to include this CSS and a PostCSS/LightningCSS plugin can post-process the CSS file after the fact.
Challenge
I am unable to figure out a valid format for CSS data URL that can be put into a JS import statement.
I tried to come up with the simplest possible example of trying to inject
body{background:pink}
and tried the following import statements:I wasn't able to get any of them work in a fresh NextJS example. Webpack did not understand any of these imports.
I tried the same in Vite with similar results.
Is there a particular way to make bundlers bundle CSS provided this way?
Is this approach even feasible? I'm putting up this PR in case someone has further insight here.
We are independently working on a CLI to work around bundlers entirely in the meantime.