1
0
mirror of https://github.com/angular/angular-cli.git synced 2025-05-20 21:42:38 +08:00

refactor(@angular/build): also add server.preTransformRequests

5c1360179c moved `preTransformRequests` from the `server` to `dev` section. But vite, still uses the `server` section in such cases bcdb51a1ac/packages/vite/src/node/server/index.ts (L673) and
bcdb51a1ac/packages/vite/src/node/server/middlewares/indexHtml.ts (L475)
This commit is contained in:
Alan Agius 2025-02-06 19:47:36 +00:00 committed by Alan Agius
parent 414736bc0f
commit 17a7b8cf01

@ -734,6 +734,7 @@ function updateResultRecord(
}
}
// eslint-disable-next-line max-lines-per-function
export async function setupServer(
serverOptions: NormalizedDevServerOptions,
outputFiles: Map<string, OutputFileRecord>,
@ -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,
@ -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,
},