This file provides guidance when working with code in this repository.
@angular-schule/prerender-format is an Angular CLI builder that wraps @angular/build:application. With "prerender": { "format": "file" }, prerendered routes are written as foo.html instead of foo/index.html, so static hosts serve /foo without a trailing slash redirect. It implements the idea from angular/angular-cli#29173; the pull request angular/angular-cli#34180 adds the same option to Angular itself. Structure and conventions follow angular-cli-ghpages.
All development commands must be run from the src directory:
cd srcIMPORTANT: The src/.npmrc file contains ignore-scripts=false to override global npm settings. DO NOT DELETE OR MODIFY this file - it's required for build scripts to run.
npm run buildBuild process: prebuild (clean) → build (tsc) → postbuild (copy metadata, schema, README and LICENSE to dist/).
npm run build:schemaapplication/schema.json is generated: the schema of @angular/build:application from the installed version plus a separate object with format in the oneOf of prerender, as in the pull request, so format cannot be combined with routesFile and discoverRoutes. format is required in that object, so {} keeps matching the object of @angular/build only. Regenerate it after updating @angular/build and commit the result. npm test fails if it is out of sync.
npm testFor testing changes locally with an Angular project:
-
Build and pack from
src/dist:cd src npm run build cd dist npm pack
-
In your Angular test project:
npm install --save-dev /path/to/angular-schule-prerender-format-X.X.X.tgz ng add @angular-schule/prerender-format ng build
Publishing uses npm Trusted Publishers with OIDC – no tokens stored in CI!
- Go to Actions → Publish to npm
- Click Run workflow → select branch
- Leave "Dry-run" checked to test, or uncheck for real publish
- Wait for approval (environment
npm-publish)
Publishes with provenance attestation for supply chain security.
The trusted publisher on npmjs.com (package settings, GitHub Actions: angular-schule / prerender-format / npm-publish.yml / environment npm-publish) needs Allowed actions: Allow npm publish checked. Without it, only npm stage publish is allowed, and the workflow fails with E403 … OIDC permission denied for this action.
For pre-release versions, after publishing:
npm dist-tag add @angular-schule/prerender-format@X.X.X-rc.X nextThe option must never make a build fail. Whenever the "file" format does not apply, log a warning and keep the behavior of @angular/build:application (<route>/index.html). No throw and no try/catch for control flow: functions that can fail return a result (see InstallResult). The only exceptions are the SchematicsExceptions of ng add for invalid input, as the Angular schematics API expects.
-
Builder (
src/application/):builder.ts- Angular builder entry point, called byng build. Takesformatout of theprerenderoption (toApplicationOptions()) and delegates tobuildApplication. WithoutputMode,@angular/buildignoresprerender, so the builder drops it there and applies onlyformat. Ifprerenderis set to anything other than an object withformat, the builder warns with the rule and the message of the pull request. Whenever the "file" format does not apply (a server is produced, the internals of@angular/builddiffer, nothing went through the wrapper), it logs a warning and the build behaves like@angular/build:application.ships-server.ts- The rule for "this build ships an SSR server", shared by builder andng add.file-format.ts- Wraps the internalprerenderPages()of@angular/build.execute-post-bundle.jsreads it from the module's exports object at call time, so replacing the export takes effect for regular and localized builds.schema.json- Generated, see above.
-
Schematic (
src/ng-add.ts):- Implements
ng add @angular-schule/prerender-format - Swaps the build target's builder and sets
"prerender": { "format": "file" }; stops ifprerendercontainsroutesFileordiscoverRoutes, which cannot be combined withformat - Warns if the build target or one of its configurations produces an SSR server
- Implements
prerenderPages() in @angular/build/src/utils/server-rendering/prerender.js is not public. If the module or the export is missing, installFileFormat() returns the reason and the builder warns instead of patching, and file-format.spec.ts checks the call site in execute-post-bundle.js. The package supports Angular 22 only. .github/scripts/test-angular-app.sh builds a fresh Angular app (lowest and latest 22.x in CI) and checks ng add, the server warning, and the "file" output for two locales.