Skip to content

Commit 1739924

Browse files
committed
perf(@angular-devkit/build-angular): start SSR dependencies optimization before the first request
Vite will only start dependency optimization of SSR modules when the first request comes in. In some cases, this causes a long waiting time. To mitigate this, we call `ssrLoadModule` to initiate this process before the first request.
1 parent 64fdb31 commit 1739924

File tree

1 file changed

+13
-1
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+13
-1
lines changed

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,20 @@ export async function* serveWithVite(
216216
);
217217

218218
server = await createServer(serverConfiguration);
219-
220219
await server.listen();
220+
221+
if (browserOptions.ssr) {
222+
/**
223+
* Vite will only start dependency optimization of SSR modules when the first request comes in.
224+
* In some cases, this causes a long waiting time. To mitigate this, we call `ssrLoadModule` to
225+
* initiate this process before the first request.
226+
*
227+
* NOTE: This will intentionally fail from the unknown module, but currently there is no other way
228+
* to initiate the SSR dep optimizer.
229+
*/
230+
void server.ssrLoadModule('<deps-caller>').catch(() => {});
231+
}
232+
221233
const urls = server.resolvedUrls;
222234
if (urls && (urls.local.length || urls.network.length)) {
223235
serverUrl = new URL(urls.local[0] ?? urls.network[0]);

0 commit comments

Comments
 (0)