Skip to content

Commit 13427ba

Browse files
committed
docs: fix build target resolution precedence and add prerenderTarget examples
Complete remaining audit TODOs (D1, D2, PR1, PR2) to address documentation gaps: 1. D1 - CRITICAL FIX: Correct Build Target Resolution in CLAUDE.md - Previous docs incorrectly stated buildTarget was tried first - Code shows browserTarget || buildTarget (browserTarget has precedence) - Updated with correct precedence: prerenderTarget > browserTarget > buildTarget > default - Added implementation references (builder.ts:23-26, 45-50) 2. D2 - Clarify browserTarget in schema.json - Updated description to explain it's a legacy alias for buildTarget - Added precedence notes (browserTarget > buildTarget, prerenderTarget > both) - Recommends using buildTarget instead for new projects 3. PR1 - Add Comprehensive prerenderTarget Documentation (README.md) - New section explaining when to use prerenderTarget (SSG, Angular Universal) - Complete angular.json example showing prerender + deploy targets - Example workflow: ng deploy with prerenderTarget - Documented target precedence and interaction with --no-build 4. PR2 - CLI vs Builder Parameter Clarification (README_standalone.md) - New section explaining Builder-only parameters - Lists buildTarget, browserTarget, prerenderTarget, noBuild, baseHref - Example standalone workflows (build separately, then deploy) - Example SSG workflow (prerender, then deploy) - Clarifies why these don't work with npx angular-cli-ghpages All tests pass (377 tests) with no regressions. Addresses audit findings: documentation now matches actual code behavior and provides complete examples for prerenderTarget usage.
1 parent 5900e53 commit 13427ba

File tree

4 files changed

+105
-6
lines changed

4 files changed

+105
-6
lines changed

CLAUDE.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,18 @@ actions.ts (deploy function)
133133

134134
### Build Target Resolution
135135

136-
**Important:** With Angular 17+, the build target resolution is complex due to different builder types. The code tries to guess the correct build target:
137-
138-
1. First tries explicit `--build-target` option
139-
2. Falls back to `${project}:build:production`
140-
3. For prerendering: uses `prerenderTarget` or `${project}:prerender:production`
136+
**Important:** With Angular 17+, the build target resolution follows a strict precedence order. The builder evaluates targets in this order and uses the first one found:
137+
138+
**Precedence (highest to lowest):**
139+
1. `prerenderTarget` - For SSG/prerendering builds (if specified, overrides all others)
140+
2. `browserTarget` - Legacy/alternative build target (if specified)
141+
3. `buildTarget` - Standard build target (if specified)
142+
4. Default - `${project}:build:production`
143+
144+
**Implementation details:**
145+
- Static build target: `browserTarget || buildTarget || default` (see `src/deploy/builder.ts:23-26`)
146+
- Final target: `prerenderTarget || staticBuildTarget` (see `src/deploy/builder.ts:45-50`)
147+
- If `prerenderTarget` is set, it takes absolute precedence regardless of other targets
141148

142149
Output directory resolution:
143150
- Checks `angular.json` for `outputPath`

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,59 @@ NOW:
259259
ng deploy --build-target=test
260260
```
261261

262+
#### --prerender-target <a name="prerender-target"></a>
263+
264+
- **optional**
265+
- Default: `undefined` (string)
266+
- Example:
267+
- `ng deploy --prerender-target=myapp:prerender:production`
268+
269+
For applications using Static Site Generation (SSG), you can specify a prerender target instead of a build target. This is useful when your Angular application uses the `@angular/ssr` package and you want to deploy the prerendered output.
270+
271+
**When to use prerenderTarget:**
272+
- Your project has a `prerender` target configured in `angular.json`
273+
- You want to deploy statically prerendered HTML files
274+
- You're using Angular Universal or `@angular/ssr` for static prerendering
275+
276+
**Example configuration in angular.json:**
277+
278+
```json
279+
{
280+
"projects": {
281+
"my-app": {
282+
"architect": {
283+
"prerender": {
284+
"builder": "@angular-devkit/build-angular:prerender",
285+
"options": {
286+
"routes": ["/", "/about", "/contact"]
287+
},
288+
"configurations": {
289+
"production": {
290+
"browserTarget": "my-app:build:production"
291+
}
292+
}
293+
},
294+
"deploy": {
295+
"builder": "angular-cli-ghpages:deploy",
296+
"options": {
297+
"prerenderTarget": "my-app:prerender:production",
298+
"baseHref": "/my-app/"
299+
}
300+
}
301+
}
302+
}
303+
}
304+
}
305+
```
306+
307+
Now you can simply run:
308+
309+
```sh
310+
ng deploy
311+
```
312+
313+
**Target Precedence:** If `prerenderTarget` is specified, it takes precedence over both `buildTarget` and `browserTarget`. This command has no effect if the option `--no-build` is active.
314+
262315
#### --no-build <a name="no-build"></a>
263316

264317
- **optional**

docs/README_standalone.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,45 @@ ionic build --prod -- --base-href=https://USERNAME.github.io/REPOSITORY_NAME/`
5151
npx angular-cli-ghpages --dir=www
5252
```
5353

54+
## Build Target Parameters (Angular Builder Only)
55+
56+
The following parameters are **only available** when using `ng deploy` (Angular Builder integration) and are **not supported** by the standalone CLI:
57+
58+
- `--build-target` / `buildTarget`
59+
- `--browser-target` / `browserTarget`
60+
- `--prerender-target` / `prerenderTarget`
61+
- `--no-build` / `noBuild`
62+
- `--base-href` / `baseHref` (only as a build option; use `ng build --base-href` instead)
63+
64+
These parameters control Angular CLI's build process integration and automatic build triggering.
65+
66+
**When using the standalone CLI** (`npx angular-cli-ghpages`):
67+
- You must **build your project separately** before deployment
68+
- Use `--dir` to specify the pre-built output directory
69+
- The standalone CLI will **not** trigger any build process
70+
71+
**Example standalone workflow:**
72+
73+
```bash
74+
# 1. Build your project first
75+
ng build --configuration=production --base-href=/my-app/
76+
77+
# 2. Then deploy the built output
78+
npx angular-cli-ghpages --dir=dist/my-app/browser
79+
```
80+
81+
**For SSG/Prerendering with standalone CLI:**
82+
83+
```bash
84+
# 1. Prerender your project first
85+
ng run my-app:prerender:production
86+
87+
# 2. Then deploy the prerendered output
88+
npx angular-cli-ghpages --dir=dist/my-app/browser
89+
```
90+
91+
If you need automatic build integration, use `ng deploy` instead of the standalone CLI. See the [main README](../README.md) for Angular Builder usage.
92+
5493
## Extra
5594
5695
For your convenience, the command will recognize the [environment variable](https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings) `GH_TOKEN` and will replace this pattern in the `--repo` string.

src/deploy/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"browserTarget": {
1515
"type": "string",
16-
"description": "A named build target, as specified in the `configurations` section of angular.json. Each named target is accompanied by a configuration of option defaults for that target. This is equivalent to calling the command `ng build --configuration=XXX`."
16+
"description": "Legacy alias for buildTarget. A named build target, as specified in the `configurations` section of angular.json. Note: browserTarget takes precedence over buildTarget if both are specified, but prerenderTarget takes precedence over both. Most users should use buildTarget instead."
1717
},
1818
"prerenderTarget": {
1919
"type": "string",

0 commit comments

Comments
 (0)