fix(css): resolve tsconfig paths in CSS and Sass @import#22775
Open
shulaoda wants to merge 1 commit into
Open
Conversation
0b78d2b to
72e7617
Compare
72e7617 to
4ea8cd2
Compare
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.
Description
close #22766
Since the oxc-resolver upgrade in Vite 8.1,
resolve.tsconfigPathsstopped resolvingpathsaliases inside CSS@importand Sass@use, such as@import "@/styles/main.css".oxc-resolver only applies a tsconfig's
pathsto a file that tsconfig owns through itsfilesorinclude. For CSS@import, Vite passed a synthetic<dir>/*importer that has no file extension, so no tsconfig ever owns it and thepathsaliases are skipped.The fix passes the real importing file as the importer: CSS (postcss-import) uses the
@importAtRule's source file, and Sass already usescontext.containingUrl. Because tsconfig matches by extension, CSS/Sass files must be declared explicitly to receivepaths, for exampleinclude: ["src", "src/**/*.css", "src/**/*.scss"]. This is documented underresolve.tsconfigPaths.Less is not supported: its plugin API only exposes the importer's directory, not the file, so Vite cannot tell the resolver which tsconfig owns it. Use a relative path or
resolve.aliasfor@importin Less. This is documented and locked in by a negative test.playground/resolve-tsconfig-pathsgains CSS@importand Sass@usecases that resolve viapaths, plus a Less case asserting the alias stays unresolved.Additional
I looked into supporting Less by overriding
getPathin its file-manager plugin so the importer's file (not just its directory) is exposed to Vite, but that repurposes a method Less relies on internally for directory derivation and is too hacky, so Less is left unsupported for now.