diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index be0984508c09b3..06c73b9d443549 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -561,16 +561,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 +637,17 @@ 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' }, () => { + const externalOnLoadResult: OnLoadResult = { + loader: 'js', + contents: 'export default {}', + } + return externalOnLoadResult + }) }, } }