File tree Expand file tree Collapse file tree 5 files changed +16
-2
lines changed
packages/vite/src/node/plugins Expand file tree Collapse file tree 5 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ import {
8282 urlRE ,
8383} from '../utils'
8484import type { Logger } from '../logger'
85- import { cleanUrl , slash } from '../../shared/utils'
85+ import { cleanUrl , isWindows , slash } from '../../shared/utils'
8686import { createBackCompatIdResolver } from '../idResolver'
8787import type { ResolveIdFn } from '../idResolver'
8888import { PartialEnvironment } from '../baseEnvironment'
@@ -1162,8 +1162,14 @@ function createCSSResolvers(config: ResolvedConfig): CSSAtImportResolvers {
11621162 preferRelative : true ,
11631163 } )
11641164 sassResolve = async ( ...args ) => {
1165+ // the modern API calls `canonicalize` with resolved file URLs
1166+ // for relative URLs before raw specifiers
11651167 if ( args [ 1 ] . startsWith ( 'file://' ) ) {
1166- args [ 1 ] = fileURLToPath ( args [ 1 ] )
1168+ args [ 1 ] = fileURLToPath ( args [ 1 ] , {
1169+ windows :
1170+ // file:///foo cannot be converted to path with windows mode
1171+ isWindows && args [ 1 ] . startsWith ( 'file:///' ) ? false : undefined ,
1172+ } )
11671173 }
11681174 return resolver ( ...args )
11691175 }
Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ test('sass', async () => {
101101 expect ( await getColor ( partialImport ) ) . toBe ( 'orchid' )
102102 expect ( await getColor ( await page . $ ( '.sass-file-absolute' ) ) ) . toBe ( 'orange' )
103103 expect ( await getColor ( await page . $ ( '.sass-dir-index' ) ) ) . toBe ( 'orange' )
104+ expect ( await getColor ( await page . $ ( '.sass-root-relative' ) ) ) . toBe ( 'orange' )
104105
105106 if ( isBuild ) return
106107
Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ <h1>CSS</h1>
4343 @import "file:///xxx/absolute-path.scss" should be orange
4444 </ p >
4545 < p class ="sass-dir-index "> @import "./dir" should be orange</ p >
46+ < p class ="sass-root-relative ">
47+ @import "/nested/root-relative.scss" should be orange
48+ </ p >
4649
4750 < p class ="less "> Less: This should be blue</ p >
4851 < p class ="less-at-import ">
Original file line number Diff line number Diff line change 11@use ' sass:string' ;
2+ @use ' /nested/root-relative' ; // root relative path
23
34@import ' ./css-in-scss.css' ;
45
Original file line number Diff line number Diff line change 1+ .sass-root-relative {
2+ color : orange ;
3+ }
You can’t perform that action at this time.
0 commit comments