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

refactor(@angular-devkit/build-angular): prevent vite from resolving explicit external dependencies #26129

Merged
merged 1 commit into from Oct 26, 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
Expand Up @@ -391,6 +391,9 @@ export async function setupServer(
watch: {
ignored: ['**/*'],
},
// This is needed when `externalDependencies` is used to prevent Vite load errors.
// NOTE: If Vite adds direct support for externals, this can be removed.
preTransformRequests: externalMetadata.explicit.length === 0,
},
ssr: {
// Exclude any provided dependencies (currently build defined externals)
Expand All @@ -403,6 +406,13 @@ export async function setupServer(
// Ensures plugin hooks run before built-in Vite hooks
enforce: 'pre',
async resolveId(source, importer) {
// Prevent vite from resolving an explicit external dependency (`externalDependencies` option)
if (externalMetadata.explicit.includes(source)) {
// This is still not ideal since Vite will still transform the import specifier to
// `/@id/${source}` but is currently closer to a raw external than a resolved file path.
return source;
}

if (importer && source.startsWith('.')) {
// Remove query if present
const [importerFile] = importer.split('?', 1);
Expand Down