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/build): also add server.preTransformRequests #29582

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/angular/build/src/builders/dev-server/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ function updateResultRecord(
}
}

// eslint-disable-next-line max-lines-per-function
export async function setupServer(
serverOptions: NormalizedDevServerOptions,
outputFiles: Map<string, OutputFileRecord>,
Expand Down Expand Up @@ -776,6 +777,15 @@ export async function setupServer(
break;
}

/**
* Required when using `externalDependencies` to prevent Vite load errors.
*
* @note Can be removed if Vite introduces native support for externals.
* @note Vite misresolves browser modules in SSR when accessing URLs with multiple segments
* (e.g., 'foo/bar'), as they are not correctly re-based from the base href.
*/
const preTransformRequests =
externalMetadata.explicitBrowser.length === 0 && ssrMode === ServerSsrMode.NoSsr;
const cacheDir = join(serverOptions.cacheOptions.path, serverOptions.buildTarget.project, 'vite');
const configuration: InlineConfig = {
configFile: false,
Expand Down Expand Up @@ -806,15 +816,10 @@ export async function setupServer(
preserveSymlinks,
},
dev: {
// This is needed when `externalDependencies` is used to prevent Vite load errors.
// NOTE: If Vite adds direct support for externals, this can be removed.
// NOTE: Vite breaks the resolution of browser modules in SSR
// when accessing a url with two or more segments (e.g., 'foo/bar'),
// as they are not re-based from the base href.
preTransformRequests:
externalMetadata.explicitBrowser.length === 0 && ssrMode === ServerSsrMode.NoSsr,
preTransformRequests,
},
server: {
preTransformRequests,
warmup: {
ssrFiles,
},
Expand Down