Skip to content

Commit 07a8ffd

Browse files
committed
fix(@angular-devkit/build-angular): keep dependencies pre-bundling validate between builds
Prior to this commit, the pre-bundling of dependencies was being invalidated for each build. This is because vite uses parts of the config among other things to generate a hash. In our case the config was not always consistent for the same project between different builds. The main 2 problems areas were: - Random `root` path - `include` and `exclude` arrays were not always in the same order.
1 parent 7cb5d35 commit 07a8ffd

File tree

1 file changed

+7
-2
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+7
-2
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type { json, logging } from '@angular-devkit/core';
1212
import type { Plugin } from 'esbuild';
1313
import { lookup as lookupMimeType } from 'mrmime';
1414
import assert from 'node:assert';
15-
import { randomUUID } from 'node:crypto';
1615
import { readFile } from 'node:fs/promises';
1716
import { ServerResponse } from 'node:http';
1817
import { dirname, extname, join, relative } from 'node:path';
@@ -192,6 +191,12 @@ export async function* serveWithVite(
192191
externalMetadata.explicit.push(...explicit);
193192
externalMetadata.implicitServer.push(...implicitServer);
194193
externalMetadata.implicitBrowser.push(...implicitBrowser);
194+
195+
// The below needs to be sorted as Vite uses these options are part of the hashing invalidation algorithm.
196+
// See: https://github.com/vitejs/vite/blob/0873bae0cfe0f0718ad2f5743dd34a17e4ab563d/packages/vite/src/node/optimizer/index.ts#L1203-L1239
197+
externalMetadata.explicit.sort();
198+
externalMetadata.implicitServer.sort();
199+
externalMetadata.implicitBrowser.sort();
195200
}
196201

197202
if (server) {
@@ -405,7 +410,7 @@ export async function setupServer(
405410

406411
// Path will not exist on disk and only used to provide separate path for Vite requests
407412
const virtualProjectRoot = normalizePath(
408-
join(serverOptions.workspaceRoot, `.angular/vite-root/${randomUUID()}/`),
413+
join(serverOptions.workspaceRoot, `.angular/vite-root`, serverOptions.buildTarget.project),
409414
);
410415

411416
const serverExplicitExternal = [

0 commit comments

Comments
 (0)