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: esbuild glob import resolve error #15140

Merged
Merged
Changes from 2 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
38 changes: 38 additions & 0 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,21 @@ function esbuildScanPlugin(
}
}

const globImportOnLoadCallback: (
args: OnLoadArgs,
) => Promise<OnLoadResult | null | undefined> = async ({ path: p }) => {
const externalLoadResult: OnLoadResult = {
loader: 'js',
contents: '\nexport default {}',
}
if (!entries.includes(p)) {
return externalLoadResult
}
if (SPECIAL_QUERY_RE.test(p)) {
return externalLoadResult
}
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
}

// extract scripts inside HTML-like files and treat it as a js module
build.onLoad(
{ filter: htmlTypesRE, namespace: 'html' },
Expand All @@ -498,6 +513,29 @@ function esbuildScanPlugin(
{ filter: htmlTypesRE, namespace: 'file' },
htmlTypeOnLoadCallback,
)
// css
build.onLoad(
{ filter: CSS_LANGS_RE, namespace: 'file' },
globImportOnLoadCallback,
)
// json & wasm
build.onLoad(
{ filter: /\.(json|json5|wasm)$/, namespace: 'file' },
globImportOnLoadCallback,
)
// known asset types
build.onLoad(
{
filter: new RegExp(`\\.(${KNOWN_ASSET_TYPES.join('|')})$`),
namespace: 'file',
},
globImportOnLoadCallback,
)
// known vite query types: ?worker, ?raw
build.onLoad(
{ filter: SPECIAL_QUERY_RE, namespace: 'file' },
globImportOnLoadCallback,
)
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved

// bare imports: record and externalize ----------------------------------
build.onResolve(
Expand Down