Skip to content

Commit

Permalink
refactor(@angular/build): also add server.preTransformRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 committed Feb 6, 2025
1 parent 414736b commit 17a7b8c
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit 17a7b8c

Please sign in to comment.