piral-ng 1.0.0-pre.2296 → 1.0.1-beta.5640

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +709 -41
  3. package/common/NgExtension.d.ts +14 -0
  4. package/common/ResourceUrlPipe.d.ts +10 -0
  5. package/common/SharedModule.d.ts +10 -0
  6. package/common/esm2022/NgExtension.mjs +47 -0
  7. package/common/esm2022/ResourceUrlPipe.mjs +23 -0
  8. package/common/esm2022/SharedModule.mjs +25 -0
  9. package/common/esm2022/piral-ng-common.mjs +5 -0
  10. package/common/esm2022/public_api.mjs +4 -0
  11. package/common/fesm2022/piral-ng-common.mjs +93 -0
  12. package/common/fesm2022/piral-ng-common.mjs.map +1 -0
  13. package/common/index.d.ts +1 -0
  14. package/common/package.json +35 -0
  15. package/common/piral-ng-common.js +3 -0
  16. package/common/public_api.d.ts +3 -0
  17. package/convert.d.ts +17 -7
  18. package/convert.js +17 -11
  19. package/esm/RoutingService.d.ts +13 -0
  20. package/esm/RoutingService.js +109 -0
  21. package/esm/RoutingService.js.map +1 -0
  22. package/esm/bootstrap.d.ts +6 -5
  23. package/esm/bootstrap.js +52 -87
  24. package/esm/bootstrap.js.map +1 -1
  25. package/esm/common/NgExtension.d.ts +11 -0
  26. package/esm/common/NgExtension.js +41 -0
  27. package/esm/common/NgExtension.js.map +1 -0
  28. package/esm/common/ResourceUrlPipe.d.ts +7 -0
  29. package/esm/common/ResourceUrlPipe.js +18 -0
  30. package/esm/common/ResourceUrlPipe.js.map +1 -0
  31. package/esm/common/SharedModule.d.ts +3 -0
  32. package/esm/common/SharedModule.js +21 -0
  33. package/esm/common/SharedModule.js.map +1 -0
  34. package/esm/common/public_api.d.ts +3 -0
  35. package/esm/common/public_api.js +4 -0
  36. package/esm/common/public_api.js.map +1 -0
  37. package/esm/converter.d.ts +10 -2
  38. package/esm/converter.js +35 -16
  39. package/esm/converter.js.map +1 -1
  40. package/esm/create.d.ts +2 -16
  41. package/esm/create.js +9 -13
  42. package/esm/create.js.map +1 -1
  43. package/esm/module.d.ts +24 -0
  44. package/esm/module.js +131 -0
  45. package/esm/module.js.map +1 -0
  46. package/esm/queue.d.ts +1 -1
  47. package/esm/queue.js +3 -3
  48. package/esm/queue.js.map +1 -1
  49. package/esm/startup.d.ts +8 -0
  50. package/esm/startup.js +115 -0
  51. package/esm/startup.js.map +1 -0
  52. package/esm/types.d.ts +71 -3
  53. package/esm/utils.d.ts +18 -0
  54. package/esm/utils.js +46 -0
  55. package/esm/utils.js.map +1 -0
  56. package/extend-webpack.js +107 -0
  57. package/lib/RoutingService.d.ts +13 -0
  58. package/lib/RoutingService.js +112 -0
  59. package/lib/RoutingService.js.map +1 -0
  60. package/lib/bootstrap.d.ts +6 -5
  61. package/lib/bootstrap.js +55 -91
  62. package/lib/bootstrap.js.map +1 -1
  63. package/lib/common/NgExtension.d.ts +11 -0
  64. package/lib/common/NgExtension.js +44 -0
  65. package/lib/common/NgExtension.js.map +1 -0
  66. package/lib/common/ResourceUrlPipe.d.ts +7 -0
  67. package/lib/common/ResourceUrlPipe.js +21 -0
  68. package/lib/common/ResourceUrlPipe.js.map +1 -0
  69. package/lib/common/SharedModule.d.ts +3 -0
  70. package/lib/common/SharedModule.js +24 -0
  71. package/lib/common/SharedModule.js.map +1 -0
  72. package/lib/common/public_api.d.ts +3 -0
  73. package/lib/common/public_api.js +7 -0
  74. package/lib/common/public_api.js.map +1 -0
  75. package/lib/converter.d.ts +10 -2
  76. package/lib/converter.js +36 -17
  77. package/lib/converter.js.map +1 -1
  78. package/lib/create.d.ts +2 -16
  79. package/lib/create.js +10 -14
  80. package/lib/create.js.map +1 -1
  81. package/lib/index.js +1 -1
  82. package/lib/module.d.ts +24 -0
  83. package/lib/module.js +139 -0
  84. package/lib/module.js.map +1 -0
  85. package/lib/queue.d.ts +1 -1
  86. package/lib/queue.js +3 -3
  87. package/lib/queue.js.map +1 -1
  88. package/lib/startup.d.ts +8 -0
  89. package/lib/startup.js +120 -0
  90. package/lib/startup.js.map +1 -0
  91. package/lib/types.d.ts +71 -3
  92. package/lib/utils.d.ts +18 -0
  93. package/lib/utils.js +55 -0
  94. package/lib/utils.js.map +1 -0
  95. package/package.json +45 -18
  96. package/src/RoutingService.ts +114 -0
  97. package/src/bootstrap.ts +57 -104
  98. package/src/common/NgExtension.ts +33 -0
  99. package/src/common/ResourceUrlPipe.ts +12 -0
  100. package/src/common/SharedModule.ts +18 -0
  101. package/src/common/index.d.ts +1 -0
  102. package/src/common/ng-package.json +11 -0
  103. package/src/common/package.json +19 -0
  104. package/src/common/piral-ng-common.js +3 -0
  105. package/src/common/public_api.ts +3 -0
  106. package/src/converter.ts +58 -20
  107. package/src/create.ts +6 -23
  108. package/src/module.ts +163 -0
  109. package/src/queue.ts +1 -1
  110. package/src/startup.ts +148 -0
  111. package/src/types.ts +73 -3
  112. package/src/utils.ts +69 -0
  113. package/convert.ts +0 -16
  114. package/esm/extension.d.ts +0 -1
  115. package/esm/extension.js +0 -41
  116. package/esm/extension.js.map +0 -1
  117. package/lib/extension.d.ts +0 -1
  118. package/lib/extension.js +0 -45
  119. package/lib/extension.js.map +0 -1
  120. package/src/extension.ts +0 -29
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
- [![Piral Logo](https://github.com/smapiot/piral/raw/master/docs/assets/logo.png)](https://piral.io)
1
+ [![Piral Logo](https://github.com/smapiot/piral/raw/main/docs/assets/logo.png)](https://piral.io)
2
2
 
3
- # [Piral Ng](https://piral.io) · [![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/smapiot/piral/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/piral-ng.svg?style=flat)](https://www.npmjs.com/package/piral-ng) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://jestjs.io) [![Gitter Chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/piral-io/community)
3
+ # [Piral Ng](https://piral.io) · [![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/smapiot/piral/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/piral-ng.svg?style=flat)](https://www.npmjs.com/package/piral-ng) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://jestjs.io) [![Gitter Chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/piral-io/community)
4
4
 
5
- This is a plugin that only has a peer dependency to `piral-core`. What `piral-ng` brings to the table is a set of Pilet API extensions that can be used with `piral` or `piral-core`.
5
+ This is a plugin that only has a peer dependency to `rxjs`, `@angular/core` and related packages. What `piral-ng` brings to the table is a set of Pilet API extensions that can be used with `piral` or `piral-core`.
6
6
 
7
- The set includes an Angular converter for any component registration, as well as a `fromNg` shortcut and a `NgExtension` component.
7
+ The set includes an Angular converter for any component registration, as well as a `fromNg` shortcut, a `defineNgModule` function, and a `NgExtension` component.
8
8
 
9
9
  By default, these API extensions are not integrated in `piral`, so you'd need to add them to your Piral instance.
10
10
 
@@ -12,6 +12,10 @@ By default, these API extensions are not integrated in `piral`, so you'd need to
12
12
 
13
13
  The following functions are brought to the Pilet API.
14
14
 
15
+ ### `defineNgModule()`
16
+
17
+ Communicates the usage of a pre-defined Angular module to Piral. Components declared/exported in the module will be bootstrapped within this module.
18
+
15
19
  ### `fromNg()`
16
20
 
17
21
  Transforms a standard Angular component into a component that can be used in Piral, essentially wrapping it with a reference to the corresponding converter.
@@ -26,7 +30,7 @@ The extension slot module to be used in Angular components. This is not really n
26
30
 
27
31
  You can use the `fromNg` function from the Pilet API to convert your Angular components to components usable by your Piral instance.
28
32
 
29
- Example use:
33
+ ### Example Usage
30
34
 
31
35
  ```ts
32
36
  import { PiletApi } from '<name-of-piral-instance>';
@@ -37,17 +41,129 @@ export function setup(piral: PiletApi) {
37
41
  }
38
42
  ```
39
43
 
44
+ We recommend that you still put these components into modules as you would normally do. In order for Piral to use that module you need to define it first. This also allows you to use special Piral declarations such as the `NgExtension` or the `ResourceUrlPipe`. All these declarations come with the `SharedModule` available via import from `piral-ng/common`.
45
+
46
+ Example (app) module:
47
+
48
+ ```ts
49
+ import { NgModule } from '@angular/core';
50
+ import { SharedModule } from 'piral-ng/common';
51
+ import { AngularPage } from './AngularPage';
52
+
53
+ @NgModule({
54
+ imports: [SharedModule],
55
+ declarations: [AngularPage],
56
+ exports: [AngularPage]
57
+ })
58
+ export class AppModule {}
59
+ ```
60
+
61
+ Now the example above changes:
62
+
63
+ ```ts
64
+ import { PiletApi } from '<name-of-piral-instance>';
65
+ import { AppModule } from './AppModule';
66
+ import { AngularPage } from './AngularPage';
67
+
68
+ export function setup(piral: PiletApi) {
69
+ // this "teaches" Piral about the given module
70
+ piral.defineNgModule(AppModule);
71
+
72
+ // since we export the AngularPage from the defined module
73
+ // Piral will use the AppModule for bootstrapping the Ng app
74
+ piral.registerPage('/sample', piral.fromNg(AngularPage));
75
+ }
76
+ ```
77
+
78
+ ### Lazy Loading
79
+
80
+ Even better, you can also lazy load the respective Angular module and components using the callback-based overload of `defineNgModule`:
81
+
82
+ ```ts
83
+ import { PiletApi } from '<name-of-piral-instance>';
84
+
85
+ export function setup(piral: PiletApi) {
86
+ // this "teaches" Piral about the given module, which is lazy loaded
87
+ // important; in this case `./AppModule.ts` has a `default` export
88
+ const loadComponent = piral.defineNgModule(() => import('./AppModule'));
89
+
90
+ // to fully lazy load we cannot reference the class anymore;
91
+ // instead we reference the selector of the component
92
+ piral.registerPage('/sample', loadComponent('angular-page'));
93
+ }
94
+ ```
95
+
96
+ In the example above, the `AngularPage` would have been defined to look like
97
+
98
+ ```js
99
+ // ...
100
+ @Component({
101
+ // ...
102
+ selector: 'angular-page',
103
+ })
104
+ export class AngularPage { /* ... */ }
105
+ ```
106
+
107
+ which defines the selector (`angular-page`) matching the specified selector in the `setup` function.
108
+
109
+ ### Standalone Components
110
+
111
+ The `piral-ng` plugin also supports Angular standalone components as rendering source.
112
+
113
+ Standalone components can also be used with lazy loading.
114
+
115
+ ```ts
116
+ import { PiletApi } from '<name-of-piral-instance>';
117
+
118
+ export function setup(piral: PiletApi) {
119
+ // Just make sure that `AngularPage` exports the component as `default` export
120
+ piral.registerPage('/sample', piral.fromNg(() => import('./AngularPage')));
121
+ }
122
+ ```
123
+
124
+ ### Angular Options
125
+
126
+ You can optionally provide Options to `defineNgModule`, which are identical to those given to `bootstrapModule` during the Angular boot process. See https://angular.io/api/core/PlatformRef#bootstrapModule for possible values.
127
+
128
+ This is mainly used to allow an Angular Pilet to run without `zone.js` as described [here](https://angular.io/guide/zone#noopzone).
129
+
130
+ ```ts
131
+ import { PiletApi } from '<name-of-piral-instance>';
132
+ import { AppModule } from './AppModule';
133
+ import { AngularPage } from './AngularPage';
134
+
135
+ export function setup(piral: PiletApi) {
136
+ piral.defineNgModule(AppModule, { ngZone: 'noop' });
137
+
138
+ piral.registerPage('/sample', piral.fromNg(AngularPage));
139
+ }
140
+ ```
141
+
40
142
  Within Angular components the Piral Angular extension component can be used by referring to `extension-component`, e.g.,
41
143
 
42
144
  ```html
43
145
  <extension-component name="name-of-extension"></extension-component>
44
146
  ```
45
147
 
148
+ For specifying `params` you may use data binding. Example:
149
+
150
+ ```html
151
+ <extension-component name="foo" [params]="{ foo: 2, bar: 'hello' }"></extension-component>
152
+ ```
153
+
154
+ The `ResourceUrlPipe` is there to get the correct paths for images that are just copied to the output directory. The pipe can be used in HTML like this:
155
+
156
+ ```html
157
+ <img width="250" [src]="'images/coffee.jpg' | resourceUrl" alt="Coffee" />
158
+ ```
159
+
160
+ In the example the relative path `images/coffee.jpg` will be expanded to a full URL rooted at the pilet's origin.
161
+
46
162
  Alternatively, if `piral-ng` has not been added to the Piral instance you can install and use the package also from a pilet directly.
47
163
 
48
164
  ```ts
49
165
  import { PiletApi } from '<name-of-piral-instance>';
50
- import { fromNg } from 'piral-ng';
166
+ import { fromNg } from 'piral-ng/convert';
51
167
  import { AngularPage } from './AngularPage';
52
168
 
53
169
  export function setup(piral: PiletApi) {
@@ -55,32 +171,139 @@ export function setup(piral: PiletApi) {
55
171
  }
56
172
  ```
57
173
 
174
+ Also, here you can make use of the `defineNgModule` function:
175
+
176
+ ```ts
177
+ import { PiletApi } from '<name-of-piral-instance>';
178
+ import { fromNg, defineNgModule } from 'piral-ng/convert';
179
+ import { AngularPage } from './AngularPage';
180
+ import { AngularModule } from './AngularModule';
181
+
182
+ export function setup(piral: PiletApi) {
183
+ defineNgModule(AngularModule);
184
+
185
+ piral.registerPage('/sample', fromNg(AngularPage));
186
+ }
187
+ ```
188
+
189
+ For components, such as the `AngularPage` a `template` should be specified.
190
+
191
+ ```ts
192
+ import { Component } from '@angular/core';
193
+
194
+ @Component({
195
+ template: `
196
+ <div class="page">
197
+ <h3>Angular Page: {{ counter }}</h3>
198
+ <button (click)="increment()">Increment</button>
199
+ <button (click)="decrement()">Decrement</button>
200
+ </div>
201
+ `,
202
+ })
203
+ export class AngularPage {
204
+ public counter = 0;
205
+
206
+ constructor() {}
207
+
208
+ increment() {
209
+ this.counter += 1;
210
+ }
211
+
212
+ decrement() {
213
+ this.counter -= 1;
214
+ }
215
+ }
216
+ ```
217
+
218
+ If you don't want to inline the `template` then just `require` the contents, e.g.,
219
+
220
+ ```js
221
+ // ...
222
+ @Component({
223
+ template: require('./AngularPage.html'),
224
+ })
225
+ export class AngularPage { /* ... */ }
226
+ ```
227
+
228
+ where you may need to tell your bundler how to treat these HTML files (i.e., transform these references to strings directly in the bundle).
229
+
230
+ As an alternative, consider using Webpack with the `@ngtools/webpack` library. This allows you have a *webpack.config.js* like:
231
+
232
+ ```js
233
+ const { AngularWebpackPlugin } = require('@ngtools/webpack');
234
+ const CopyPlugin = require("copy-webpack-plugin");
235
+ const { resolve } = require("path");
236
+
237
+ module.exports = (config) => {
238
+ config.module.rules.filter(m => m.test.toString() === /\.css$/i.toString()).forEach(m => {
239
+ m.exclude = /\.component.css$/i;
240
+ });
241
+
242
+ config.module.rules.filter(m => m.test.toString() === /\.s[ac]ss$/i.toString()).forEach(m => {
243
+ m.exclude = /\.component.s[ac]ss$/i;
244
+ });
245
+
246
+ const ruleIndex = config.module.rules.findIndex(m => m.test.toString() === /\.tsx?$/i.toString());
247
+
248
+ config.module.rules.splice(ruleIndex, 1,
249
+ {
250
+ test: /\.[jt]sx?$/,
251
+ loader: '@ngtools/webpack',
252
+ },
253
+ {
254
+ test: /\.component.html$/i,
255
+ use: ["to-string-loader", "html-loader?esModule=false"],
256
+ },
257
+ {
258
+ test: /\.component.css$/i,
259
+ use: ["to-string-loader", "css-loader?esModule=false"],
260
+ },
261
+ {
262
+ test: /\.component.s[ac]ss$/i,
263
+ use: ["to-string-loader", "css-loader?esModule=false", "sass-loader"],
264
+ });
265
+
266
+ config.plugins.push(
267
+ new AngularWebpackPlugin({
268
+ tsconfig: 'tsconfig.json',
269
+ jitMode: true,
270
+ }),
271
+ new CopyPlugin({
272
+ patterns: [
273
+ { from: resolve(__dirname, "src/assets") },
274
+ ],
275
+ }),
276
+ )
277
+
278
+
279
+ return config;
280
+ };
281
+ ```
282
+
283
+ **Note**: You must install these dependencies (also things like `copy-webpack-plugin`) yourself. `piral-ng` does not come with any dependencies for development.
284
+
58
285
  :::
59
286
 
60
287
  ::: summary: For Piral instance developers
61
288
 
62
289
  The provided library only brings API extensions for pilets to a Piral instance. The Piral instance still needs to be configured properly to support Angular 2+.
63
290
 
64
- The following polyfills / vendor libs should be imported *before* any other package.
291
+ The following (Angular) packages should be installed:
65
292
 
66
- ```ts
67
- import '@angular/platform-browser';
68
- import '@angular/platform-browser-dynamic';
69
- import '@angular/core';
70
- import '@angular/common';
71
- import '@angular/http';
72
- import '@core-js/es7/reflect';
73
- import 'zone.js/dist/zone';
74
- ```
293
+ - `@angular/common`
294
+ - `@angular/core`
295
+ - `@angular/platform-browser`
296
+ - `@angular/platform-browser-dynamic`
297
+ - `@angular/router`
298
+ - `rxjs`
75
299
 
76
- Furthermore, switching on the production mode may be useful.
300
+ The following polyfills/vendor libs should be imported *before* any other package.
77
301
 
78
302
  ```ts
79
- import { enableProdMode } from '@angular/core';
80
-
81
- if (process.env.NODE_ENV === 'production') {
82
- enableProdMode();
83
- }
303
+ import 'core-js/es/reflect';
304
+ import 'core-js/stable/reflect';
305
+ import 'core-js/features/reflect';
306
+ import 'zone.js';
84
307
  ```
85
308
 
86
309
  For the setup itself you'll need to import `createNgApi` from the `piral-ng` package.
@@ -103,16 +326,17 @@ The related packages should be shared with the pilets via the *package.json*:
103
326
 
104
327
  ```json
105
328
  {
106
- "pilets": {
107
- "externals": [
108
- "@angular/common",
109
- "@angular/compiler",
110
- "@angular/core",
111
- "@angular/platform-browser",
112
- "@angular/platform-browser-dynamic",
113
- "rxjs",
114
- "zone.js"
115
- ]
329
+ "importmap": {
330
+ "imports": {
331
+ "@angular/common": "",
332
+ "@angular/compiler": "",
333
+ "@angular/core": "",
334
+ "@angular/platform-browser": "",
335
+ "@angular/platform-browser-dynamic": "",
336
+ "piral-ng/common": "",
337
+ "rxjs": "",
338
+ "zone.js": ""
339
+ }
116
340
  }
117
341
  }
118
342
  ```
@@ -125,17 +349,34 @@ Depending on your Angular needs you'd want to share more packages.
125
349
 
126
350
  Depending on the mounted component different services are injected. the following table lists the names of the injected services per component type.
127
351
 
128
- | Component | Props | Piral | Context |
129
- |-----------|------------------|---------|-----------|
130
- | Tile | `TileProps` | `Piral` | `Context` |
131
- | Page | `PageProps` | `Piral` | `Context` |
132
- | Modal | `ModalProps` | `Piral` | `Context` |
133
- | Extension | `ExtensionProps` | `Piral` | `Context` |
134
- | Menu | `MenuProps` | `Piral` | `Context` |
352
+ | Component | Props | Piral | Context |
353
+ |-----------|---------|---------|-----------|
354
+ | Tile | `Props` | `piral` | `Context` |
355
+ | Page | `Props` | `piral` | `Context` |
356
+ | Modal | `Props` | `piral` | `Context` |
357
+ | Extension | `Props` | `piral` | `Context` |
358
+ | Menu | `Props` | `piral` | `Context` |
135
359
 
136
360
  To use such a service the `@Inject` decorator should be used with the explicit name.
137
361
 
138
- The following code snippet illustrates the injection of the `TileProps` service into a sample tile component.
362
+ The following code snippet illustrates the injection of the `Props` service from an `TileProps` interface into a sample tile component.
363
+
364
+ ```ts
365
+ @Component({
366
+ template: `
367
+ <div class="tile">
368
+ <p>{{ props.rows }} rows and {{ props.columns }} columns</p>
369
+ </div>
370
+ `,
371
+ })
372
+ export class SampleTileComponent {
373
+ constructor(@Inject('Props') public props: TileComponentProps<any>) {}
374
+ }
375
+ ```
376
+
377
+ ## Dynamic Props
378
+
379
+ For `Props` there is also the possibility to use `@Input` for making them reactive, i.e., notify the Angular component when they changed.
139
380
 
140
381
  ```ts
141
382
  @Component({
@@ -146,10 +387,437 @@ The following code snippet illustrates the injection of the `TileProps` service
146
387
  `,
147
388
  })
148
389
  export class SampleTileComponent {
149
- constructor(@Inject('TileProps') public props: TileComponentProps<any>) {}
390
+ @Input('Props') public props: TileComponentProps<any>;
391
+
392
+ constructor() {}
393
+ }
394
+ ```
395
+
396
+ ## Converting an Angular Application to a Pilet
397
+
398
+ Depending on the kind of Angular application this may be rather straight forward or very difficult. Since we cannot discuss all possible edge cases we will assume the standard scenario. If you need more help then don't hesitate to contact us.
399
+
400
+ First, you'll need to get rid of the Angular CLI. In most cases adding a Webpack configuration should be sufficient. The Webpack configuration can be similar to the one presented above. In many cases you can use the convenience `extend-webpack` module.
401
+
402
+ This is how your *webpack.config.js* can look like:
403
+
404
+ ```js
405
+ const extendWebpack = require('piral-ng/extend-webpack');
406
+
407
+ module.exports = extendWebpack({
408
+ ngOptions: {
409
+ jitMode: false,
410
+ },
411
+ });
412
+ ```
413
+
414
+ For using `piral-ng/extend-webpack` you must have installed:
415
+
416
+ - `copy-webpack-plugin`
417
+ - `@ngtools/webpack`
418
+ - `to-string-loader`
419
+ - `html-loader`
420
+ - `webpack`, e.g., via `piral-cli-webpack5`
421
+
422
+ You can do that via:
423
+
424
+ ```sh
425
+ npm i copy-webpack-plugin @ngtools/webpack to-string-loader html-loader piral-cli-webpack5 --save-dev
426
+ ```
427
+
428
+ The available options for `piral-ng/extend-webpack` are:
429
+
430
+ - `ngOptions` (providing input to the `AngularWebpackPlugin` class)
431
+ - `patterns` (providing input to the Webpack `copy-webpack-plugin`)
432
+ - `compilerOptions` (providing input to the `angularCompilerOptions` section of the *tsconfig.json*)
433
+
434
+ For AoT (i.e. `jitMode: false`) to work correctly the `compilationMode: 'partial'` has to be set. If you use the `piral-ng/extend-webpack` helper as shown above this will be configured correctly for you.
435
+
436
+ ::: failure: AoT does not work with dependency sharing
437
+ For AoT to work correctly the Angular sources need to be bundled. This is not the case in scenarios where you installed `piral-ng` as a plugin in your shell or distribute the Angular packages as shared dependencies from your app shell.
438
+ :::
439
+
440
+ If you have set up the build process then you need to make sure that your application has an entry point (*index.ts*). That entry point has to be a valid pilet entry module. It may look as follows:
441
+
442
+ ```ts
443
+ import { PiletApi } from '<your-app-shell>';
444
+
445
+ export function setup(api: PiletApi) {
446
+
150
447
  }
151
448
  ```
152
449
 
450
+ You can remove your *main.ts* (or similar) containing
451
+
452
+ ```ts
453
+ platformBrowserDynamic()
454
+ .bootstrapModule(AppModule)
455
+ .catch(err => console.error(err));
456
+ ```
457
+
458
+ as the bootstrapping is done by Piral. Instead, you now need to define your `AppModule` in the pilet:
459
+
460
+ ```ts
461
+ import { PiletApi } from '<your-app-shell>';
462
+ import { AppModule } from './app/AppModule.ts';
463
+
464
+ export function setup(api: PiletApi) {
465
+ api.defineNgModule(AppModule);
466
+ }
467
+ ```
468
+
469
+ Now you can register the exported components from the `AppModule` in the various parts. Example:
470
+
471
+ ```ts
472
+ import { PiletApi } from '<your-app-shell>';
473
+ import { AppModule } from './app/AppModule.ts';
474
+ import { AppComponent } from './app/AppComponent.ts';
475
+
476
+ export function setup(api: PiletApi) {
477
+ api.defineNgModule(AppModule);
478
+
479
+ api.registerPage('/foo/*', api.fromNg(AppComponent));
480
+ }
481
+ ```
482
+
483
+ In the given example we register a single page, however, with all subpages resolving to the same page. Within the page we may use the Angular Router to determine what content to show.
484
+
485
+ The content may remain pretty much unchanged. Routing should be done either via the Angular Router (internal) or via the React Router (across components) automatically. The thing you'll need to pay attention to is the usage of resources. Since the resource will be available available to the location of the pilet (e.g., if the pilet's main bundle is located at `https://yourcdn.com/your-pilet/1.0.0/index.js` then resources need to be relative to `https://yourcdn.com/your-pilet/1.0.0/`).
486
+
487
+ In general you may also want to convert the `templateUrl` (and `styleUrls`) properties of your components (to `template` and `styles`). If you set up the bundler as recommended then it would still work though.
488
+
489
+ ::: warning: Prefer not to use `templateUrl`
490
+ In many Angular projects you still find `templateUrl`, which would be transformed to a `template` by the Angular CLI during build. If you want to achieve the same using, e.g., Webpack, then use a custom loader such as [angularjs-template-loader](https://www.npmjs.com/package/angularjs-template-loader).
491
+
492
+ The same issue applies to `styleUrls`, which should be replaced by `styles`.
493
+
494
+ If you still need to use `templateUrl` (or `styleUrls`) then take a look below at the Webpack config file.
495
+ :::
496
+
497
+ ## Angular Versions
498
+
499
+ This plugin works with all versions of Angular (right now 2 - 12). Support for Angular.js (also known as Angular 1) is given via `piral-ngjs`.
500
+
501
+ ### Angular 2
502
+
503
+ Angular 2 works with some configuration (see below) even though the usage of annotations (internally) is slightly different in `piral-ng`.
504
+
505
+ The basic dependencies look as follows:
506
+
507
+ ```json
508
+ {
509
+ "@angular/common": "^2",
510
+ "@angular/compiler": "^2",
511
+ "@angular/core": "^2",
512
+ "@angular/router": "^2",
513
+ "@angular/platform-browser": "^2",
514
+ "@angular/platform-browser-dynamic": "^2",
515
+ "core-js": "^3.15.2",
516
+ "rxjs": "^5.0",
517
+ "zone.js": "~0.9"
518
+ }
519
+ ```
520
+
521
+ ### Angular 3
522
+
523
+ Was never released. Not covered.
524
+
525
+ ### Angular 4
526
+
527
+ Angular 4 works even though the usage of annotations (internally) is slightly different in `piral-ng`.
528
+
529
+ The basic dependencies look as follows:
530
+
531
+ ```json
532
+ {
533
+ "@angular/common": "^4",
534
+ "@angular/compiler": "^4",
535
+ "@angular/core": "^4",
536
+ "@angular/router": "^4",
537
+ "@angular/platform-browser": "^4",
538
+ "@angular/platform-browser-dynamic": "^4",
539
+ "core-js": "^3.15.2",
540
+ "rxjs": "^5.0.0",
541
+ "zone.js": "~0.9"
542
+ }
543
+ ```
544
+
545
+ ### Angular 5
546
+
547
+ In general, Angular 5 seems to work.
548
+
549
+ The basic dependencies look as follows:
550
+
551
+ ```json
552
+ {
553
+ "@angular/common": "^5",
554
+ "@angular/compiler": "^5",
555
+ "@angular/core": "^5",
556
+ "@angular/router": "^5",
557
+ "@angular/platform-browser": "^5",
558
+ "@angular/platform-browser-dynamic": "^5",
559
+ "core-js": "^3.15.2",
560
+ "rxjs": "^5.0.0",
561
+ "zone.js": "~0.9"
562
+ }
563
+ ```
564
+
565
+ ### Angular 6
566
+
567
+ In general, Angular 6 seems to work.
568
+
569
+ The basic dependencies look as follows:
570
+
571
+ ```json
572
+ {
573
+ "@angular/common": "^6",
574
+ "@angular/compiler": "^6",
575
+ "@angular/core": "^6",
576
+ "@angular/router": "^6",
577
+ "@angular/platform-browser": "^6",
578
+ "@angular/platform-browser-dynamic": "^6",
579
+ "core-js": "^3.15.2",
580
+ "rxjs": "^6.0.0",
581
+ "zone.js": "~0.9"
582
+ }
583
+ ```
584
+
585
+ ### Angular 7
586
+
587
+ In general, Angular 7 seems to work.
588
+
589
+ The basic dependencies look as follows:
590
+
591
+ ```json
592
+ {
593
+ "@angular/common": "^7",
594
+ "@angular/compiler": "^7",
595
+ "@angular/core": "^7",
596
+ "@angular/router": "^7",
597
+ "@angular/platform-browser": "^7",
598
+ "@angular/platform-browser-dynamic": "^7",
599
+ "core-js": "^3.15.2",
600
+ "rxjs": "^6.4",
601
+ "zone.js": "~0.9"
602
+ }
603
+ ```
604
+
605
+ ### Angular 8
606
+
607
+ In general, Angular 8 seems to work and is **supported**.
608
+
609
+ The basic dependencies look as follows:
610
+
611
+ ```json
612
+ {
613
+ "@angular/common": "^8",
614
+ "@angular/compiler": "^8",
615
+ "@angular/core": "^8",
616
+ "@angular/router": "^8",
617
+ "@angular/platform-browser": "^8",
618
+ "@angular/platform-browser-dynamic": "^8",
619
+ "core-js": "^3.15.2",
620
+ "rxjs": "^6.4",
621
+ "zone.js": "~0.9"
622
+ }
623
+ ```
624
+
625
+ ### Angular 9
626
+
627
+ In general, Angular 9 seems to work and is **supported**.
628
+
629
+ The basic dependencies look as follows:
630
+
631
+ ```json
632
+ {
633
+ "@angular/common": "^9",
634
+ "@angular/compiler": "^9",
635
+ "@angular/core": "^9",
636
+ "@angular/router": "^9",
637
+ "@angular/platform-browser": "^9",
638
+ "@angular/platform-browser-dynamic": "^9",
639
+ "core-js": "^3.15.2",
640
+ "rxjs": "~6.5",
641
+ "zone.js": "~0.9"
642
+ }
643
+ ```
644
+
645
+ ### Angular 10
646
+
647
+ In general, Angular 10 seems to work and is **supported**.
648
+
649
+ The basic dependencies look as follows:
650
+
651
+ ```json
652
+ {
653
+ "@angular/common": "^10",
654
+ "@angular/compiler": "^10",
655
+ "@angular/core": "^10",
656
+ "@angular/router": "^10",
657
+ "@angular/platform-browser": "^10",
658
+ "@angular/platform-browser-dynamic": "^10",
659
+ "core-js": "^3.15.2",
660
+ "rxjs": "~6.5",
661
+ "zone.js": "~0.9"
662
+ }
663
+ ```
664
+
665
+ ### Angular 11
666
+
667
+ In general, Angular 11 seems to work and is **supported**.
668
+
669
+ The basic dependencies look as follows:
670
+
671
+ ```json
672
+ {
673
+ "@angular/common": "^11",
674
+ "@angular/compiler": "^11",
675
+ "@angular/core": "^11",
676
+ "@angular/router": "^11",
677
+ "@angular/platform-browser": "^11",
678
+ "@angular/platform-browser-dynamic": "^11",
679
+ "core-js": "^3.15.2",
680
+ "rxjs": "~6.5",
681
+ "zone.js": "~0.9"
682
+ }
683
+ ```
684
+
685
+ ### Angular 12
686
+
687
+ In general, Angular 12 seems to work and is **supported**.
688
+
689
+ The basic dependencies look as follows:
690
+
691
+ ```json
692
+ {
693
+ "@angular/common": "^12",
694
+ "@angular/compiler": "^12",
695
+ "@angular/core": "^12",
696
+ "@angular/router": "^12",
697
+ "@angular/platform-browser": "^12",
698
+ "@angular/platform-browser-dynamic": "^12",
699
+ "core-js": "^3.15.2",
700
+ "rxjs": "~6.4",
701
+ "zone.js": "0.11.4"
702
+ }
703
+ ```
704
+
705
+ ### Angular 13
706
+
707
+ In general, Angular 13 seems to work and is **supported**.
708
+
709
+ The basic dependencies look as follows:
710
+
711
+ ```json
712
+ {
713
+ "@angular/common": "^13",
714
+ "@angular/compiler": "^13",
715
+ "@angular/core": "^13",
716
+ "@angular/router": "^13",
717
+ "@angular/platform-browser": "^13",
718
+ "@angular/platform-browser-dynamic": "^13",
719
+ "core-js": "^3.19.0",
720
+ "rxjs": "^7.4",
721
+ "zone.js": "0.11.4"
722
+ }
723
+ ```
724
+
725
+ Besides the usual imports the explicit import of the `@angular/compiler` package may be necessary.
726
+
727
+ So include in your app shell as preamble:
728
+
729
+ ```js
730
+ import 'core-js/proposals/reflect-metadata';
731
+ import '@angular/compiler';
732
+ ```
733
+
734
+ ### Angular 14
735
+
736
+ In general, Angular 14 seems to work and is **supported**.
737
+
738
+ The basic dependencies look as follows:
739
+
740
+ ```json
741
+ {
742
+ "@angular/common": "^14",
743
+ "@angular/compiler": "^14",
744
+ "@angular/core": "^14",
745
+ "@angular/router": "^14",
746
+ "@angular/platform-browser": "^14",
747
+ "@angular/platform-browser-dynamic": "^14",
748
+ "core-js": "^3.19.0",
749
+ "rxjs": "^7.4",
750
+ "zone.js": "~0.12.0"
751
+ }
752
+ ```
753
+
754
+ Besides the usual imports the explicit import of the `@angular/compiler` package may be necessary.
755
+
756
+ So include in your app shell as preamble:
757
+
758
+ ```js
759
+ import 'core-js/proposals/reflect-metadata';
760
+ import '@angular/compiler';
761
+ ```
762
+
763
+ ### Angular 15
764
+
765
+ In general, Angular 15 seems to work and is **supported**.
766
+
767
+ The basic dependencies look as follows:
768
+
769
+ ```json
770
+ {
771
+ "@angular/common": "^15",
772
+ "@angular/compiler": "^15",
773
+ "@angular/core": "^15",
774
+ "@angular/router": "^15",
775
+ "@angular/platform-browser": "^15",
776
+ "@angular/platform-browser-dynamic": "^15",
777
+ "core-js": "^3.19.0",
778
+ "rxjs": "^7.4",
779
+ "zone.js": "~0.13.0"
780
+ }
781
+ ```
782
+
783
+ Besides the usual imports the explicit import of the `@angular/compiler` package may be necessary.
784
+
785
+ So include in your app shell as preamble:
786
+
787
+ ```js
788
+ import 'core-js/proposals/reflect-metadata';
789
+ import '@angular/compiler';
790
+ ```
791
+
792
+ ### Angular 16
793
+
794
+ In general, Angular 16 seems to work and is **supported**.
795
+
796
+ The basic dependencies look as follows:
797
+
798
+ ```json
799
+ {
800
+ "@angular/common": "^16",
801
+ "@angular/compiler": "^16",
802
+ "@angular/core": "^16",
803
+ "@angular/router": "^16",
804
+ "@angular/platform-browser": "^16",
805
+ "@angular/platform-browser-dynamic": "^16",
806
+ "core-js": "^3.19.0",
807
+ "rxjs": "^7.4",
808
+ "zone.js": "~0.13.0"
809
+ }
810
+ ```
811
+
812
+ Besides the usual imports, the explicit import of the `@angular/compiler` package may be necessary. TypeScript has to be higher than 4.8 (4.9 or later).
813
+
814
+ So include in your app shell as preamble:
815
+
816
+ ```js
817
+ import 'core-js/proposals/reflect-metadata';
818
+ import '@angular/compiler';
819
+ ```
820
+
153
821
  ## License
154
822
 
155
823
  Piral is released using the MIT license. For more information see the [license file](./LICENSE).