diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index 8f2475709003c0..d596d39d1a62e9 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -563,9 +563,6 @@ export async function toAbsoluteGlob( custom: { 'vite:import-glob': { isSubImportsPattern } }, })) || glob, ) - if (isSubImportsPattern) { - return join(root, resolved) - } if (isAbsolute(resolved)) { return pre + globSafeResolvedPath(resolved, glob) } diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index ccffd1c152972c..d31b40dd7a7cbd 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -203,7 +203,7 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin { id = resolvedImports if (resolveOpts.custom?.['vite:import-glob']?.isSubImportsPattern) { - return id + return normalizePath(path.join(root, id)) } } diff --git a/playground/glob-import/__tests__/glob-import.spec.ts b/playground/glob-import/__tests__/glob-import.spec.ts index e7c7719357fd2c..bdfb4e92119c23 100644 --- a/playground/glob-import/__tests__/glob-import.spec.ts +++ b/playground/glob-import/__tests__/glob-import.spec.ts @@ -240,6 +240,10 @@ test('escapes special chars in globs without mangling user supplied glob suffix' expect(expectedNames).toEqual(foundAliasNames) }) -test('sub imports', async () => { - expect(await page.textContent('.sub-imports')).toMatch('bar foo') +test('subpath imports', async () => { + expect(await page.textContent('.subpath-imports')).toMatch('bar foo') +}) + +test('#alias imports', async () => { + expect(await page.textContent('.hash-alias-imports')).toMatch('bar foo') }) diff --git a/playground/glob-import/index.html b/playground/glob-import/index.html index 41e6409aea4bab..8f8d833b56625b 100644 --- a/playground/glob-import/index.html +++ b/playground/glob-import/index.html @@ -21,20 +21,16 @@

Escape relative glob


 

Escape alias glob


-

Sub imports

-

+

Subpath imports

+

+

#alias imports

+

 

In package


 
 
 
 
 
 
-  document.querySelector('.sub-imports').textContent = Object.values(subImports)
+
diff --git a/playground/glob-import/vite.config.ts b/playground/glob-import/vite.config.ts
index 87a057ba6112ad..896c7c05768a7a 100644
--- a/playground/glob-import/vite.config.ts
+++ b/playground/glob-import/vite.config.ts
@@ -19,6 +19,7 @@ export default defineConfig({
     alias: {
       ...escapeAliases,
       '@dir': path.resolve(__dirname, './dir/'),
+      '#alias': path.resolve(__dirname, './imports-path/'),
     },
   },
   build: {