mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 06:41:45 +08:00
refactor(@angular/build): Enable SSR with Prerendering Disabled in Vite
This commit enables server-side rendering (SSR) in Vite when prerendering is turned off. It also imports `@angular/compiler` in the SSR middleware to resolve the following issue: ``` [vite] Internal server error: The injectable 'PlatformNavigation' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available. The injectable is part of a library that has been partially compiled. However, the Angular Linker has not processed the library to utilize JIT compilation as a fallback. Ideally, the library should be processed with the Angular Linker for complete AOT compilation. ``` Closes #28523
This commit is contained in:
parent
41934e7aa1
commit
c33e862328
@ -103,6 +103,7 @@ export async function* serveWithVite(
|
||||
// Disable prerendering if enabled and force SSR.
|
||||
// This is so instead of prerendering all the routes for every change, the page is "prerendered" when it is requested.
|
||||
browserOptions.prerender = false;
|
||||
browserOptions.ssr ||= true;
|
||||
}
|
||||
|
||||
// Set all packages as external to support Vite's prebundle caching
|
||||
|
@ -34,6 +34,9 @@ export function createAngularSsrInternalMiddleware(
|
||||
}
|
||||
|
||||
(async () => {
|
||||
// Load the compiler because `@angular/ssr/node` depends on `@angular/` packages,
|
||||
// which must be processed by the runtime linker, even if they are not used.
|
||||
await loadEsmModule('@angular/compiler');
|
||||
const { writeResponseToNodeResponse, createWebRequestFromNodeRequest } =
|
||||
await loadEsmModule<typeof import('@angular/ssr/node')>('@angular/ssr/node');
|
||||
|
||||
@ -76,6 +79,10 @@ export async function createAngularSsrExternalMiddleware(
|
||||
| ReturnType<typeof createAngularSsrInternalMiddleware>
|
||||
| undefined;
|
||||
|
||||
// Load the compiler because `@angular/ssr/node` depends on `@angular/` packages,
|
||||
// which must be processed by the runtime linker, even if they are not used.
|
||||
await loadEsmModule('@angular/compiler');
|
||||
|
||||
const { createWebRequestFromNodeRequest, writeResponseToNodeResponse } =
|
||||
await loadEsmModule<typeof import('@angular/ssr/node')>('@angular/ssr/node');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user