Skip to content

Commit 08e3e7a

Browse files
fix(angular): update schematics to support Angular's latest build system (#30525)
Issue number: resolves ionic-team/ionic-docs#2091 --------- ## What is the current behavior? Documentation to test `ng add` schematic for @ionic/angular is outdated & it fails when running with: ``` Invalid projectType for my-app: undefined ``` ## What is the new behavior? Fix the schematic to support the latest Angular build system & update the documentation for testing local Ionic Framework with `ng add`. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information _I am using `Angular CLI: 20.0.4`_ Run these commands first to see the error: ```sh ng new my-app --style=css --ssr=false --zoneless=false cd my-app ng add @ionic/angular --skip-confirmation ``` Switch to this branch (`fix-angular-schematics`) and then follow the [new steps](https://github.com/ionic-team/ionic-framework/blob/b9b345303c7e1446a990c11a8ae6f70c1f773493/packages/angular/README.md#testing-local-ionic-framework-with-ng-add) and confirm the error is gone. -------- `Co-authored-by: soundproofboot <[email protected]>` --------- Co-authored-by: Brandy Smith <[email protected]>
1 parent 80a111c commit 08e3e7a

File tree

2 files changed

+81
-38
lines changed

2 files changed

+81
-38
lines changed

packages/angular/README.md

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,80 @@ Ionic Angular specific building blocks on top of [@ionic/core](https://www.npmjs
1818

1919
* [MIT](https://raw.githubusercontent.com/ionic-team/ionic/main/LICENSE)
2020

21-
## Testing ng-add in ionic
22-
23-
1. Pull the latest from `main`
24-
2. Build ionic/angular: `npm run build`
25-
3. Run `npm link` from `ionic/angular/dist` directory
26-
4. Create a blank angular project
27-
28-
```
29-
ng new add-test
30-
// Say yes to including the router, we need it
31-
cd add-test
32-
```
33-
34-
5. To run schematics locally, we need the schematics-cli (once published, this will not be needed)
35-
36-
```
37-
npm install @angular-devkit/schematics-cli
38-
```
39-
40-
6. Link `@ionic/angular`
41-
42-
```
43-
npm link @ionic/angular
44-
```
45-
46-
47-
7. Run the local copy of the ng-add schematic
48-
49-
```
50-
$ npx schematics @ionic/angular:ng-add
51-
```
52-
53-
54-
You'll now be able to add ionic components to a vanilla Angular app setup.
21+
## Testing Local Ionic Framework with `ng add`
22+
23+
This guide shows you how to test the local Ionic Framework build with a new Angular application using `ng add`. This is useful for development and testing changes before publishing.
24+
25+
### Prerequisites
26+
27+
- Node.js and npm installed
28+
- Angular CLI installed globally (`npm install -g @angular/cli`)
29+
30+
### Build Local Ionic Framework
31+
32+
1. Clone the repository (if not already done):
33+
```sh
34+
git clone https://github.com/ionic-team/ionic-framework.git
35+
cd ionic-framework
36+
```
37+
38+
2. Pull the latest from `main`
39+
```sh
40+
git pull origin main
41+
```
42+
43+
3. Install dependencies and build the `core` package:
44+
```sh
45+
cd core
46+
npm install
47+
npm run build
48+
```
49+
50+
4. Install dependencies, sync the `core` build and build the Angular package:
51+
```sh
52+
cd ../packages/angular
53+
npm install
54+
npm run sync
55+
npm run build
56+
```
57+
58+
5. Create a tarball:
59+
```sh
60+
cd dist
61+
npm pack
62+
```
63+
64+
6. Copy the tarball to Downloads:
65+
```sh
66+
cp ionic-angular-*.tgz ~/Downloads/ionic-angular.tgz
67+
```
68+
69+
### Test with New Angular App
70+
71+
7. Create a new Angular app:
72+
```sh
73+
# Change to whichever directory you want the app in
74+
cd ~/Documents/
75+
ng new my-app --style=css --ssr=false --zoneless=false
76+
cd my-app
77+
```
78+
79+
8. Install the local `@ionic/angular` package:
80+
```sh
81+
npm install ~/Downloads/ionic-angular.tgz
82+
```
83+
84+
9. Run `ng add`:
85+
```sh
86+
ng add @ionic/angular --skip-confirmation
87+
```
88+
89+
10. Serve the app:
90+
```sh
91+
ng serve
92+
```
93+
94+
The local Ionic Framework build is now active in the Angular app. Changes to the Ionic source code require rebuilding the packages and reinstalling the tarball to see updates.
5595

5696
## Project Structure
5797

packages/angular/src/schematics/utils/config.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ export function writeConfig(host: Tree, config: JsonObject): void {
1717
function isAngularBrowserProject(projectConfig: any): boolean {
1818
if (projectConfig.projectType === 'application') {
1919
const buildConfig = projectConfig.architect.build;
20+
2021
// Angular 16 and lower
21-
const legacyAngularBuilder = buildConfig.builder === '@angular-devkit/build-angular:browser';
22-
// Angular 17+
23-
const modernAngularBuilder = buildConfig.builder === '@angular-devkit/build-angular:application';
22+
const legacyBrowserBuilder = buildConfig.builder === '@angular-devkit/build-angular:browser';
23+
// Angular 17
24+
const legacyApplicationBuilder = buildConfig.builder === '@angular-devkit/build-angular:application';
25+
// Angular 18+
26+
const modernApplicationBuilder = buildConfig.builder === '@angular/build:application';
2427

25-
return legacyAngularBuilder || modernAngularBuilder;
28+
return legacyBrowserBuilder || legacyApplicationBuilder || modernApplicationBuilder;
2629
}
2730

2831
return false;

0 commit comments

Comments
 (0)