From 129d0d0983285d31bed41d2c7a08c138ad32e625 Mon Sep 17 00:00:00 2001 From: Senao <48955231+XiSenao@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:43:01 +0800 Subject: [PATCH] fix(scanner): catch all external files for glob imports (#15286) --- packages/vite/src/node/optimizer/scan.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index be0984508c09b3..b28c13167e5fb6 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -550,7 +550,6 @@ function esbuildScanPlugin( // should be faster than doing it in the catch-all via js // they are done after the bare import resolve because a package name // may end with these extensions - const setupExternalize = ( filter: RegExp, doExternalize: (path: string) => boolean, @@ -561,16 +560,6 @@ function esbuildScanPlugin( external: doExternalize(path), } }) - // onResolve is not called for glob imports. - // we need to add that here as well until esbuild calls onResolve for glob imports. - // https://github.com/evanw/esbuild/issues/3317 - build.onLoad({ filter, namespace: 'file' }, () => { - const externalOnLoadResult: OnLoadResult = { - loader: 'js', - contents: 'export default {}', - } - return externalOnLoadResult - }) } // css @@ -647,6 +636,16 @@ function esbuildScanPlugin( contents, } }) + + // onResolve is not called for glob imports. + // we need to add that here as well until esbuild calls onResolve for glob imports. + // https://github.com/evanw/esbuild/issues/3317 + build.onLoad({ filter: /.*/, namespace: 'file' }, () => { + return { + loader: 'js', + contents: 'export default {}', + } + }) }, } }