Skip to content

Commit 191dd85

Browse files
committed
chore: merge main
2 parents d499b50 + ac528a4 commit 191dd85

File tree

18 files changed

+99
-29
lines changed

18 files changed

+99
-29
lines changed

docs/.vitepress/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ const additionalTitle = ((): string => {
4343
})()
4444
const versionLinks = ((): DefaultTheme.NavItemWithLink[] => {
4545
const oldVersions: DefaultTheme.NavItemWithLink[] = [
46+
{
47+
text: 'Vite 6 Docs',
48+
link: 'https://v6.vite.dev',
49+
},
4650
{
4751
text: 'Vite 5 Docs',
4852
link: 'https://v5.vite.dev',
@@ -66,7 +70,7 @@ const versionLinks = ((): DefaultTheme.NavItemWithLink[] => {
6670
case 'local':
6771
return [
6872
{
69-
text: 'Vite 6 Docs (release)',
73+
text: 'Vite 7 Docs (release)',
7074
link: 'https://vite.dev',
7175
},
7276
...oldVersions,

docs/config/server-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export default defineConfig({
254254

255255
File system watcher options to pass on to [chokidar](https://github.com/paulmillr/chokidar/tree/3.6.0#api).
256256

257-
The Vite server watcher watches the `root` and skips the `.git/`, `node_modules/`, and Vite's `cacheDir` and `build.outDir` directories by default. When updating a watched file, Vite will apply HMR and update the page only if needed.
257+
The Vite server watcher watches the `root` and skips the `.git/`, `node_modules/`, `test-results/`, and Vite's `cacheDir` and `build.outDir` directories by default. When updating a watched file, Vite will apply HMR and update the page only if needed.
258258

259259
If set to `null`, no files will be watched. `server.watcher` will provide a compatible event emitter, but calling `add` or `unwatch` will have no effect.
260260

packages/vite/src/node/plugins/css.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,23 +2448,31 @@ const makeScssWorker = (
24482448
return unquotedUrl.startsWith('#{')
24492449
}
24502450

2451-
const internalImporter: Sass.Importer<'async'> = {
2451+
const createInternalImporter = (
2452+
isForRelative: boolean,
2453+
): Sass.Importer<'async'> => ({
24522454
async canonicalize(url, context) {
2453-
const importer = context.containingUrl
2454-
? fileURLToPath(context.containingUrl)
2455-
: options.filename
2456-
const resolved = await resolvers.sass(
2457-
environment,
2458-
url,
2459-
cleanScssBugUrl(importer),
2460-
)
2461-
if (
2462-
resolved &&
2463-
(resolved.endsWith('.css') ||
2464-
resolved.endsWith('.scss') ||
2465-
resolved.endsWith('.sass'))
2466-
) {
2467-
return pathToFileURL(resolved)
2455+
if (isForRelative) {
2456+
// sass passes resolved paths for importer passed to `importer` option
2457+
const resolved = new URL(url, context.containingUrl ?? undefined)
2458+
if (fs.existsSync(resolved)) return resolved
2459+
} else {
2460+
const importer = context.containingUrl
2461+
? fileURLToPath(context.containingUrl)
2462+
: options.filename
2463+
const resolved = await resolvers.sass(
2464+
environment,
2465+
url,
2466+
cleanScssBugUrl(importer),
2467+
)
2468+
if (
2469+
resolved &&
2470+
(resolved.endsWith('.css') ||
2471+
resolved.endsWith('.scss') ||
2472+
resolved.endsWith('.sass'))
2473+
) {
2474+
return pathToFileURL(resolved)
2475+
}
24682476
}
24692477
return null
24702478
},
@@ -2487,12 +2495,13 @@ const makeScssWorker = (
24872495
result.contents ?? (await fsp.readFile(result.file, 'utf-8'))
24882496
return { contents, syntax, sourceMapUrl: canonicalUrl }
24892497
},
2490-
}
2498+
})
2499+
24912500
sassOptions.importers = [
24922501
...(sassOptions.importers ?? []),
2493-
internalImporter,
2502+
createInternalImporter(false),
24942503
]
2495-
sassOptions.importer ??= internalImporter
2504+
sassOptions.importer ??= createInternalImporter(true)
24962505

24972506
const result = await compiler.compileStringAsync(data, sassOptions)
24982507
return {

packages/vite/tsconfig.check.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"target": "ES2020",
44
"moduleResolution": "node16",
55
"module": "Node16",
6-
"lib": ["ES2020", "WebWorker"], // ES2020 is very conservative check for client types, could be bumped if needed
6+
"lib": ["ES2020"], // ES2020 is very conservative check for client types, could be bumped if needed
77
"types": [], // Avoid checking unrelated node_modules types
88
"noEmit": true,
99
"strict": true,

packages/vite/types/importGlob.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ export interface ImportGlobOptions<
3636

3737
export type GeneralImportGlobOptions = ImportGlobOptions<boolean, string>
3838

39+
/**
40+
* Declare Worker in case DOM is not added to the tsconfig lib causing
41+
* Worker interface is not defined. For developers with DOM lib added,
42+
* the Worker interface will be merged correctly.
43+
*/
44+
declare global {
45+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
46+
interface Worker {}
47+
}
48+
3949
export interface KnownAsTypeMap {
4050
raw: string
4151
url: string

playground/css/__tests__/sass-tests.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const sassTest = () => {
77
const atImport = await page.$('.sass-at-import')
88
const atImportAlias = await page.$('.sass-at-import-alias')
99
const atImportRelative = await page.$('.sass-at-import-relative')
10+
const atImportReplacementAlias = await page.$(
11+
'.sass-at-import-replacement-alias',
12+
)
1013
const urlStartsWithVariable = await page.$('.sass-url-starts-with-variable')
1114
const urlStartsWithVariableInterpolation1 = await page.$(
1215
'.sass-url-starts-with-interpolation1',
@@ -35,6 +38,7 @@ export const sassTest = () => {
3538
expect(await getBg(atImportRelative)).toMatch(
3639
isBuild ? /base64/ : '/nested/icon.png',
3740
)
41+
expect(await getColor(atImportReplacementAlias)).toBe('olive')
3842
expect(await getBg(urlStartsWithVariable)).toMatch(
3943
isBuild ? /ok-[-\w]+\.png/ : `${viteTestUrl}/ok.png`,
4044
)

playground/css/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ <h1>CSS</h1>
3636
<p class="sass-at-import-relative">
3737
@import from SASS relative: This should be olive and have bg image
3838
</p>
39+
<p class="sass-at-import-replacement-alias">
40+
@import with replacement alias from SASS: This should be olive
41+
</p>
3942
<p class="sass-partial">@import from SASS _partial: This should be orchid</p>
4043
<p class="sass-url-starts-with-variable">url starts with variable</p>
4144
<p class="sass-url-starts-with-interpolation1">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.sass-at-import-replacement-alias {
2+
color: olive;
3+
}

playground/css/sass.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@use '=/weapp.wxss'; // wxss file
1010
@use 'virtual-file-absolute';
1111
@use '=/scss-dir/main.scss'; // "./dir" reference from vite custom importer
12+
@use '=replace/nested/replacement-alias.scss';
1213

1314
.sass {
1415
/* injected via vite.config.js */

playground/css/vite.config.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,20 @@ export default defineConfig({
6262
},
6363
},
6464
resolve: {
65-
alias: {
66-
'=': __dirname,
67-
spacefolder: __dirname + '/folder with space',
68-
'#alias': __dirname + '/aliased/foo.css',
69-
'#alias?inline': __dirname + '/aliased/foo.css?inline',
70-
'#alias-module': __dirname + '/aliased/bar.module.css',
71-
},
65+
alias: [
66+
{ find: '=', replacement: __dirname },
67+
{ find: /=replace\/(.*)/, replacement: `${__dirname}/$1` },
68+
{ find: 'spacefolder', replacement: __dirname + '/folder with space' },
69+
{ find: '#alias', replacement: __dirname + '/aliased/foo.css' },
70+
{
71+
find: '#alias?inline',
72+
replacement: __dirname + '/aliased/foo.css?inline',
73+
},
74+
{
75+
find: '#alias-module',
76+
replacement: __dirname + '/aliased/bar.module.css',
77+
},
78+
],
7279
},
7380
css: {
7481
modules: {

0 commit comments

Comments
 (0)