Generate CSS after Vite handles imports during prod builds#14850
Closed
thecrypticace wants to merge 6 commits intonextfrom
Closed
Generate CSS after Vite handles imports during prod builds#14850thecrypticace wants to merge 6 commits intonextfrom
thecrypticace wants to merge 6 commits intonextfrom
Conversation
This fails so its marked as a `todo` test.
Contributor
|
We decided to keep the pre processing phase for now and fixed the issues with the following PRs: |
adamwathan
pushed a commit
that referenced
this pull request
Nov 7, 2024
Fixes #14784 This is an alternative to #14850 in which we actually perform url rewriting / rebasing ourselves. We ported a large portion of the URL-rewriting code from Vite (with attribution) to use here with some minor modifications. We've added test cases for the url rewriting so verifying individual cases is easy. We also wrote integration tests for Vite that use PostCSS and Lightning CSS that verify that files are found and inlined or relocated/renamed as necessary. We also did some manual testing in the Playground to verify that this works as expected across several CSS files and directories which you can see a screenshot from here: <img width="1344" alt="Screenshot 2024-11-05 at 10 25 16" src="https://github.com/user-attachments/assets/ff0b3ac8-cdc9-4e26-af79-36396a5b77b9"> --------- Co-authored-by: Philipp Spiess <hello@philippspiess.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When we started handling
@importourselves in #14446 we inadvertently broke Vite's URL asset url rewriting inside of some imported CSS files.For example, given the following files:
We'd flatten the import CSS and you'd end up with the following:
And, as you can see,
../image.pngdoes not exist relative to the "final" CSS. It should've been rewritten to./image.pngbut was not. Letting Vite handle the imports will rewrite these urls properly — which is what this PR does. It achieves this by running our CSS generation when typtical Vite plugins do rather than before (viaenforce: 'pre').Additionally, because we were running the generation step early, Vue had not handled
:deep(…)selectors in<style scoped>blocks yet and we were caching the unprocessed CSS. This is also fixed by this PR.Ideally both of these things would be fixable by changing how we handle imports but that will require additional APIs so this is a reasonable stopgap measure until we can do that.
Fixes #14839