Skip to content

Commit ef69998

Browse files
committed
fix(@angular-devkit/build-angular): ensure all configured assets can be served by dev server
The Vite-based development server restricts filesystem access by default. However, assets configured by the build option `assets` are intended to be accessible by the application at runtime. To ensure that these files are accessible, the allow list will now explicitly include all configured assets found during the build.
1 parent a4f32cd commit ef69998

File tree

1 file changed

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

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ export async function* serveWithVite(
212212
}
213213

214214
if (server) {
215+
// Update fs allow list to include any new assets from the build option
216+
server.config.server.fs.allow = [
217+
...new Set(...server.config.server.fs.allow, ...assetFiles.values()),
218+
];
219+
215220
handleUpdate(normalizePath, generatedFiles, server, serverOptions, context.logger);
216221
} else {
217222
const projectName = context.target?.project;
@@ -425,10 +430,11 @@ export async function setupServer(
425430
...externalMetadata.explicit,
426431
];
427432

433+
const cacheDir = join(serverOptions.cacheOptions.path, 'vite');
428434
const configuration: InlineConfig = {
429435
configFile: false,
430436
envFile: false,
431-
cacheDir: join(serverOptions.cacheOptions.path, 'vite'),
437+
cacheDir,
432438
root: virtualProjectRoot,
433439
publicDir: false,
434440
esbuild: false,
@@ -453,6 +459,13 @@ export async function setupServer(
453459
watch: {
454460
ignored: ['**/*'],
455461
},
462+
fs: {
463+
// Ensure cache directory, node modules, and all assets are accessible by the client.
464+
// The first two are required for Vite to function in prebundling mode (the default) and to load
465+
// the Vite client-side code for browser reloading. These would be available by default but when
466+
// the `allow` option is explicitly configured, they must be included manually.
467+
allow: [cacheDir, join(serverOptions.workspaceRoot, 'node_modules'), ...assets.values()],
468+
},
456469
// This is needed when `externalDependencies` is used to prevent Vite load errors.
457470
// NOTE: If Vite adds direct support for externals, this can be removed.
458471
preTransformRequests: externalMetadata.explicit.length === 0,

0 commit comments

Comments
 (0)