Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scanner): catch all external files for glob imports #15286

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 10 additions & 11 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 {}',
}
})
},
}
}
Expand Down