Skip to content

Commit 6473b01

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 cff7663 commit 6473b01

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ export async function* serveWithVite(
215215
}
216216

217217
if (server) {
218+
// Update fs allow list to include any new assets from the build option.
219+
server.config.server.fs.allow = [
220+
...new Set(...server.config.server.fs.allow, ...assetFiles.values()),
221+
];
222+
218223
handleUpdate(normalizePath, generatedFiles, server, serverOptions, context.logger);
219224
} else {
220225
const projectName = context.target?.project;
@@ -430,10 +435,11 @@ export async function setupServer(
430435
...externalMetadata.explicit,
431436
];
432437

438+
const cacheDir = join(serverOptions.cacheOptions.path, 'vite');
433439
const configuration: InlineConfig = {
434440
configFile: false,
435441
envFile: false,
436-
cacheDir: join(serverOptions.cacheOptions.path, 'vite'),
442+
cacheDir,
437443
root: virtualProjectRoot,
438444
publicDir: false,
439445
esbuild: false,
@@ -456,6 +462,13 @@ export async function setupServer(
456462
proxy,
457463
// File watching is handled by the build directly. `null` disables file watching for Vite.
458464
watch: null,
465+
fs: {
466+
// Ensure cache directory, node modules, and all assets are accessible by the client.
467+
// The first two are required for Vite to function in prebundling mode (the default) and to load
468+
// the Vite client-side code for browser reloading. These would be available by default but when
469+
// the `allow` option is explicitly configured, they must be included manually.
470+
allow: [cacheDir, join(serverOptions.workspaceRoot, 'node_modules'), ...assets.values()],
471+
},
459472
// This is needed when `externalDependencies` is used to prevent Vite load errors.
460473
// NOTE: If Vite adds direct support for externals, this can be removed.
461474
preTransformRequests: externalMetadata.explicit.length === 0,

0 commit comments

Comments
 (0)