Skip to content

Commit 2c64edb

Browse files
committed
chore: Merge branch 'main' into fix/dynamic-import-inline
2 parents 971c8a5 + 875fc11 commit 2c64edb

File tree

802 files changed

+590
-740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

802 files changed

+590
-740
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ module.exports = defineConfig({
109109
}
110110
},
111111
{
112-
files: ['packages/playground/**'],
112+
files: ['playground/**'],
113113
rules: {
114114
'node/no-extraneous-import': 'off',
115115
'node/no-extraneous-require': 'off'

.gitignore

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
.DS_Store
2-
node_modules
31
!**/glob-import/dir/node_modules
4-
dist
5-
dist-ssr
6-
TODOs.md
7-
*.log
8-
temp
9-
explorations
2+
.DS_Store
103
.idea
11-
*.local
12-
/packages/vite/LICENSE
134
*.cpuprofile
5+
*.local
6+
*.log
147
/.vscode/
8+
/packages/vite/LICENSE
9+
dist
10+
dist-ssr
11+
explorations
12+
node_modules
13+
playground-temp
14+
temp
15+
TODOs.md

.prettierignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ LICENSE.md
88
.prettierignore
99
pnpm-lock.yaml
1010
pnpm-workspace.yaml
11-
packages/playground/tsconfig-json-load-error/has-error/tsconfig.json
12-
packages/playground/html/invalid.html
13-
packages/playground/worker/classic-worker.js
11+
playground/tsconfig-json-load-error/has-error/tsconfig.json
12+
playground/html/invalid.html
13+
playground/worker/classic-worker.js

CONTRIBUTING.md

Lines changed: 8 additions & 8 deletions

docs/guide/ssr.md

Lines changed: 5 additions & 5 deletions

jest.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ const config: Config.InitialOptions = {
99
globalTeardown: './scripts/jestGlobalTeardown.cjs',
1010
testEnvironment: './scripts/jestEnv.cjs',
1111
setupFilesAfterEnv: ['./scripts/jestPerTestSetup.ts'],
12-
watchPathIgnorePatterns: ['<rootDir>/packages/temp'],
13-
modulePathIgnorePatterns: ['<rootDir>/packages/temp'],
12+
watchPathIgnorePatterns: ['<rootDir>/playground-temp'],
13+
modulePathIgnorePatterns: ['<rootDir>/playground-temp'],
1414
moduleNameMapper: {
15-
testUtils: '<rootDir>/packages/playground/testUtils.ts'
15+
testUtils: '<rootDir>/playground/testUtils.ts'
1616
},
1717
globals: {
1818
'ts-jest': {
19-
tsconfig: './packages/playground/tsconfig.json'
19+
tsconfig: './playground/tsconfig.json'
2020
}
2121
}
2222
}

packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export const eagerAs = {
3838
\\"./modules/a.ts\\": __vite_glob_5_0,
3939
\\"./modules/b.ts\\": __vite_glob_5_1
4040
};
41+
export const rawImportModule = {
42+
\\"./modules/a.ts\\": () => import(\\"./modules/a.ts?raw\\"),
43+
\\"./modules/b.ts\\": () => import(\\"./modules/b.ts?raw\\")
44+
};
4145
export const excludeSelf = {
4246
\\"./sibling.ts\\": () => import(\\"./sibling.ts\\")
4347
};
@@ -108,6 +112,10 @@ export const eagerAs = {
108112
\\"./modules/a.ts\\": __vite_glob_5_0,
109113
\\"./modules/b.ts\\": __vite_glob_5_1
110114
};
115+
export const rawImportModule = {
116+
\\"./modules/a.ts\\": () => import(\\"./modules/a.ts?raw\\"),
117+
\\"./modules/b.ts\\": () => import(\\"./modules/b.ts?raw\\")
118+
};
111119
export const excludeSelf = {
112120
\\"./sibling.ts\\": () => import(\\"./sibling.ts\\")
113121
};

packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export const eagerAs = import.meta.glob<ModuleType>(
2727
{ eager: true, as: 'raw' }
2828
)
2929

30+
export const rawImportModule = import.meta.glob(
31+
['./modules/*.ts', '!**/index.ts'],
32+
{ as: 'raw', import: '*' }
33+
)
34+
3035
export const excludeSelf = import.meta.glob(
3136
'./*.ts'
3237
// for test: annotation contain ")"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const htmlProxyMap = new WeakMap<
6464

6565
// HTML Proxy Transform result are stored by config
6666
// `${hash(importer)}_${query.index}` -> transformed css code
67-
// PS: key like `hash(/vite/packages/playground/assets/index.html)_1`)
67+
// PS: key like `hash(/vite/playground/assets/index.html)_1`)
6868
export const htmlProxyResult = new Map<string, string>()
6969

7070
export function htmlInlineProxyPlugin(config: ResolvedConfig): Plugin {

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,15 @@ export async function parseImportGlob(
217217
}
218218

219219
if (options.as && forceDefaultAs.includes(options.as)) {
220-
if (options.import && options.import !== 'default')
220+
if (
221+
options.import &&
222+
options.import !== 'default' &&
223+
options.import !== '*'
224+
)
221225
throw err(
222-
`Option "export" can only be "default" when "as" is "${options.as}", but got "${options.import}"`
226+
`Option "import" can only be "default" or "*" when "as" is "${options.as}", but got "${options.import}"`
223227
)
224-
options.import = 'default'
228+
options.import = options.import || 'default'
225229
}
226230

227231
if (options.as && options.query)
@@ -358,21 +362,24 @@ export async function transformGlobImport(
358362

359363
importPath = `${importPath}${importQuery}`
360364

365+
const importKey =
366+
options.import && options.import !== '*'
367+
? options.import
368+
: undefined
369+
361370
if (options.eager) {
362371
const variableName = `${importPrefix}${index}_${i}`
363-
const expression = options.import
364-
? `{ ${options.import} as ${variableName} }`
372+
const expression = importKey
373+
? `{ ${importKey} as ${variableName} }`
365374
: `* as ${variableName}`
366375
staticImports.push(
367376
`import ${expression} from ${JSON.stringify(importPath)}`
368377
)
369378
objectProps.push(`${JSON.stringify(filePath)}: ${variableName}`)
370379
} else {
371380
let importStatement = `import(${JSON.stringify(importPath)})`
372-
if (options.import)
373-
importStatement += `.then(m => m[${JSON.stringify(
374-
options.import
375-
)}])`
381+
if (importKey)
382+
importStatement += `.then(m => m[${JSON.stringify(importKey)}])`
376383
objectProps.push(
377384
`${JSON.stringify(filePath)}: () => ${importStatement}`
378385
)

0 commit comments

Comments
 (0)