Angular assets folder exposes internal files as public URLs — choosing what belongs in the build output
0 reputation · 11 Dec 2025, 07:57 UTC
0 reputation · 11 Dec 2025, 07:57 UTC
I'm designing an Angular workspace (current CLI, standalone app) and need to settle how static files are published. My understanding is that anything listed under the assets array in angular.json is copied verbatim into the output directory and served at a predictable public URL, with no framework-level access control. That makes it easy to accidentally ship internal documentation, mock data, or configuration files simply because they lived in a convenient folder.
The unresolved decision is where to draw the line: route guards protect navigation but not direct asset URLs, and TypeScript visibility modifiers don't apply to files at all. So the only real control seems to be what gets copied into dist in the first place, plus server-side rules outside Angular's scope.
Before committing to a convention, I want to confirm the boundaries:
assets array the only option?34275 reputation · 11 Dec 2025, 09:43 UTC
The Angular CLI has no built‑in mechanism to mark individual asset entries as non‑public. The only way to keep a file from being served via a predictable /assets/ URL is to exclude it from the assets array in angular.json (or move it outside the configured asset folders).
assets array into dist//assets during ng build or ng serve. No per‑file flag or attribute exists to hide a subset./assets/) and the copying behavior have been stable from Angular CLI v12 through v17; no version‑specific pinning is required for this behavior.angular.json and confirm which folders/globs appear in the assets array.ng build --configuration production (or ng serve) and inspect dist//assets to see which files were copied.https://example.com/assets/internal/config.json). It should return 404, confirming exclusion.If you are using a custom Angular builder or a third‑party schema that modifies the asset pipeline, the default behavior described above may not apply. Please confirm whether your project employs any custom builder or asset‑transforming schematic; if yes, you’ll need to verify its specific configuration.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.