From 2b5926a0e79ce47d22536d38eed2629d326caca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Thu, 5 Dec 2024 17:09:42 +0900 Subject: [PATCH] fix(config): bundle files referenced with imports field (#18887) --- packages/vite/src/node/config.ts | 2 +- playground/config/__tests__/config.spec.ts | 1 + playground/config/packages/entry/imports-field.ts | 1 + playground/config/packages/entry/package.json | 3 +++ playground/config/packages/entry/vite.config.ts | 2 ++ 5 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 playground/config/packages/entry/imports-field.ts diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index f5b4f83e1a6eb1..783f441fb7ea9f 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -1768,7 +1768,7 @@ async function bundleConfigFile( // externalize bare imports build.onResolve( - { filter: /^[^.].*/ }, + { filter: /^[^.#].*/ }, async ({ path: id, importer, kind }) => { if ( kind === 'entry-point' || diff --git a/playground/config/__tests__/config.spec.ts b/playground/config/__tests__/config.spec.ts index b4a665e87e41e8..0addd3929f5244 100644 --- a/playground/config/__tests__/config.spec.ts +++ b/playground/config/__tests__/config.spec.ts @@ -27,6 +27,7 @@ it('loadConfigFromFile', async () => { 4, ], ], + "importsField": "imports-field", "moduleCondition": "import condition", } `) diff --git a/playground/config/packages/entry/imports-field.ts b/playground/config/packages/entry/imports-field.ts new file mode 100644 index 00000000000000..68cdd5441cce85 --- /dev/null +++ b/playground/config/packages/entry/imports-field.ts @@ -0,0 +1 @@ +export default 'imports-field' diff --git a/playground/config/packages/entry/package.json b/playground/config/packages/entry/package.json index bb0e07d0af7389..49687b7453c123 100644 --- a/playground/config/packages/entry/package.json +++ b/playground/config/packages/entry/package.json @@ -3,5 +3,8 @@ "type": "module", "dependencies": { "@vite/test-config-plugin-module-condition": "link:../plugin-module-condition" + }, + "imports": { + "#imports-field": "./imports-field.ts" } } diff --git a/playground/config/packages/entry/vite.config.ts b/playground/config/packages/entry/vite.config.ts index 7a4e9a682ae040..49c94e1515eccf 100644 --- a/playground/config/packages/entry/vite.config.ts +++ b/playground/config/packages/entry/vite.config.ts @@ -1,7 +1,9 @@ import moduleCondition from '@vite/test-config-plugin-module-condition' import { array } from '../siblings/foo' +import importsField from '#imports-field' export default { array, moduleCondition, + importsField, }