piral-ng 1.0.0-pre.2296 → 1.0.0

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 +701 -42
  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 +51 -16
  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,34 +171,132 @@ export function setup(piral: PiletApi) {
55
171
  }
56
172
  ```
57
173
 
58
- :::
59
-
60
- ::: summary: For Piral instance developers
174
+ Also, here you can make use of the `defineNgModule` function:
61
175
 
62
- 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+.
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';
63
181
 
64
- The following polyfills / vendor libs should be imported *before* any other package.
182
+ export function setup(piral: PiletApi) {
183
+ defineNgModule(AngularModule);
65
184
 
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';
185
+ piral.registerPage('/sample', fromNg(AngularPage));
186
+ }
74
187
  ```
75
188
 
76
- Furthermore, switching on the production mode may be useful.
189
+ For components, such as the `AngularPage` a `template` should be specified.
77
190
 
78
191
  ```ts
79
- import { enableProdMode } from '@angular/core';
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;
80
205
 
81
- if (process.env.NODE_ENV === 'production') {
82
- enableProdMode();
206
+ constructor() {}
207
+
208
+ increment() {
209
+ this.counter += 1;
210
+ }
211
+
212
+ decrement() {
213
+ this.counter -= 1;
214
+ }
83
215
  }
84
216
  ```
85
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
+
285
+ :::
286
+
287
+ ::: summary: For Piral instance developers
288
+
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+.
290
+
291
+ The following polyfills/vendor libs should be imported *before* any other package.
292
+
293
+ ```ts
294
+ import 'core-js/es/reflect';
295
+ import 'core-js/stable/reflect';
296
+ import 'core-js/features/reflect';
297
+ import 'zone.js';
298
+ ```
299
+
86
300
  For the setup itself you'll need to import `createNgApi` from the `piral-ng` package.
87
301
 
88
302
  ```ts
@@ -103,16 +317,17 @@ The related packages should be shared with the pilets via the *package.json*:
103
317
 
104
318
  ```json
105
319
  {
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
- ]
320
+ "importmap": {
321
+ "imports": {
322
+ "@angular/common": "",
323
+ "@angular/compiler": "",
324
+ "@angular/core": "",
325
+ "@angular/platform-browser": "",
326
+ "@angular/platform-browser-dynamic": "",
327
+ "piral-ng/common": "",
328
+ "rxjs": "",
329
+ "zone.js": ""
330
+ }
116
331
  }
117
332
  }
118
333
  ```
@@ -125,17 +340,34 @@ Depending on your Angular needs you'd want to share more packages.
125
340
 
126
341
  Depending on the mounted component different services are injected. the following table lists the names of the injected services per component type.
127
342
 
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` |
343
+ | Component | Props | Piral | Context |
344
+ |-----------|---------|---------|-----------|
345
+ | Tile | `Props` | `piral` | `Context` |
346
+ | Page | `Props` | `piral` | `Context` |
347
+ | Modal | `Props` | `piral` | `Context` |
348
+ | Extension | `Props` | `piral` | `Context` |
349
+ | Menu | `Props` | `piral` | `Context` |
135
350
 
136
351
  To use such a service the `@Inject` decorator should be used with the explicit name.
137
352
 
138
- The following code snippet illustrates the injection of the `TileProps` service into a sample tile component.
353
+ The following code snippet illustrates the injection of the `Props` service from an `TileProps` interface into a sample tile component.
354
+
355
+ ```ts
356
+ @Component({
357
+ template: `
358
+ <div class="tile">
359
+ <p>{{ props.rows }} rows and {{ props.columns }} columns</p>
360
+ </div>
361
+ `,
362
+ })
363
+ export class SampleTileComponent {
364
+ constructor(@Inject('Props') public props: TileComponentProps<any>) {}
365
+ }
366
+ ```
367
+
368
+ ## Dynamic Props
369
+
370
+ For `Props` there is also the possibility to use `@Input` for making them reactive, i.e., notify the Angular component when they changed.
139
371
 
140
372
  ```ts
141
373
  @Component({
@@ -146,10 +378,437 @@ The following code snippet illustrates the injection of the `TileProps` service
146
378
  `,
147
379
  })
148
380
  export class SampleTileComponent {
149
- constructor(@Inject('TileProps') public props: TileComponentProps<any>) {}
381
+ @Input('Props') public props: TileComponentProps<any>;
382
+
383
+ constructor() {}
384
+ }
385
+ ```
386
+
387
+ ## Converting an Angular Application to a Pilet
388
+
389
+ 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.
390
+
391
+ 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.
392
+
393
+ This is how your *webpack.config.js* can look like:
394
+
395
+ ```js
396
+ const extendWebpack = require('piral-ng/extend-webpack');
397
+
398
+ module.exports = extendWebpack({
399
+ ngOptions: {
400
+ jitMode: false,
401
+ },
402
+ });
403
+ ```
404
+
405
+ For using `piral-ng/extend-webpack` you must have installed:
406
+
407
+ - `copy-webpack-plugin`
408
+ - `@ngtools/webpack`
409
+ - `to-string-loader`
410
+ - `html-loader`
411
+ - `webpack`, e.g., via `piral-cli-webpack5`
412
+
413
+ You can do that via:
414
+
415
+ ```sh
416
+ npm i copy-webpack-plugin @ngtools/webpack to-string-loader html-loader piral-cli-webpack5 --save-dev
417
+ ```
418
+
419
+ The available options for `piral-ng/extend-webpack` are:
420
+
421
+ - `ngOptions` (providing input to the `AngularWebpackPlugin` class)
422
+ - `patterns` (providing input to the Webpack `copy-webpack-plugin`)
423
+ - `compilerOptions` (providing input to the `angularCompilerOptions` section of the *tsconfig.json*)
424
+
425
+ 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.
426
+
427
+ ::: failure: AoT does not work with dependency sharing
428
+ 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.
429
+ :::
430
+
431
+ 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:
432
+
433
+ ```ts
434
+ import { PiletApi } from '<your-app-shell>';
435
+
436
+ export function setup(api: PiletApi) {
437
+
150
438
  }
151
439
  ```
152
440
 
441
+ You can remove your *main.ts* (or similar) containing
442
+
443
+ ```ts
444
+ platformBrowserDynamic()
445
+ .bootstrapModule(AppModule)
446
+ .catch(err => console.error(err));
447
+ ```
448
+
449
+ as the bootstrapping is done by Piral. Instead, you now need to define your `AppModule` in the pilet:
450
+
451
+ ```ts
452
+ import { PiletApi } from '<your-app-shell>';
453
+ import { AppModule } from './app/AppModule.ts';
454
+
455
+ export function setup(api: PiletApi) {
456
+ api.defineNgModule(AppModule);
457
+ }
458
+ ```
459
+
460
+ Now you can register the exported components from the `AppModule` in the various parts. Example:
461
+
462
+ ```ts
463
+ import { PiletApi } from '<your-app-shell>';
464
+ import { AppModule } from './app/AppModule.ts';
465
+ import { AppComponent } from './app/AppComponent.ts';
466
+
467
+ export function setup(api: PiletApi) {
468
+ api.defineNgModule(AppModule);
469
+
470
+ api.registerPage('/foo/*', api.fromNg(AppComponent));
471
+ }
472
+ ```
473
+
474
+ 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.
475
+
476
+ 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/`).
477
+
478
+ 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.
479
+
480
+ ::: warning: Prefer not to use `templateUrl`
481
+ 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).
482
+
483
+ The same issue applies to `styleUrls`, which should be replaced by `styles`.
484
+
485
+ If you still need to use `templateUrl` (or `styleUrls`) then take a look below at the Webpack config file.
486
+ :::
487
+
488
+ ## Angular Versions
489
+
490
+ 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`.
491
+
492
+ ### Angular 2
493
+
494
+ Angular 2 works with some configuration (see below) even though the usage of annotations (internally) is slightly different in `piral-ng`.
495
+
496
+ The basic dependencies look as follows:
497
+
498
+ ```json
499
+ {
500
+ "@angular/common": "^2",
501
+ "@angular/compiler": "^2",
502
+ "@angular/core": "^2",
503
+ "@angular/router": "^2",
504
+ "@angular/platform-browser": "^2",
505
+ "@angular/platform-browser-dynamic": "^2",
506
+ "core-js": "^3.15.2",
507
+ "rxjs": "^5.0",
508
+ "zone.js": "~0.9"
509
+ }
510
+ ```
511
+
512
+ ### Angular 3
513
+
514
+ Was never released. Not covered.
515
+
516
+ ### Angular 4
517
+
518
+ Angular 4 works even though the usage of annotations (internally) is slightly different in `piral-ng`.
519
+
520
+ The basic dependencies look as follows:
521
+
522
+ ```json
523
+ {
524
+ "@angular/common": "^4",
525
+ "@angular/compiler": "^4",
526
+ "@angular/core": "^4",
527
+ "@angular/router": "^4",
528
+ "@angular/platform-browser": "^4",
529
+ "@angular/platform-browser-dynamic": "^4",
530
+ "core-js": "^3.15.2",
531
+ "rxjs": "^5.0.0",
532
+ "zone.js": "~0.9"
533
+ }
534
+ ```
535
+
536
+ ### Angular 5
537
+
538
+ In general, Angular 5 seems to work.
539
+
540
+ The basic dependencies look as follows:
541
+
542
+ ```json
543
+ {
544
+ "@angular/common": "^5",
545
+ "@angular/compiler": "^5",
546
+ "@angular/core": "^5",
547
+ "@angular/router": "^5",
548
+ "@angular/platform-browser": "^5",
549
+ "@angular/platform-browser-dynamic": "^5",
550
+ "core-js": "^3.15.2",
551
+ "rxjs": "^5.0.0",
552
+ "zone.js": "~0.9"
553
+ }
554
+ ```
555
+
556
+ ### Angular 6
557
+
558
+ In general, Angular 6 seems to work.
559
+
560
+ The basic dependencies look as follows:
561
+
562
+ ```json
563
+ {
564
+ "@angular/common": "^6",
565
+ "@angular/compiler": "^6",
566
+ "@angular/core": "^6",
567
+ "@angular/router": "^6",
568
+ "@angular/platform-browser": "^6",
569
+ "@angular/platform-browser-dynamic": "^6",
570
+ "core-js": "^3.15.2",
571
+ "rxjs": "^6.0.0",
572
+ "zone.js": "~0.9"
573
+ }
574
+ ```
575
+
576
+ ### Angular 7
577
+
578
+ In general, Angular 7 seems to work.
579
+
580
+ The basic dependencies look as follows:
581
+
582
+ ```json
583
+ {
584
+ "@angular/common": "^7",
585
+ "@angular/compiler": "^7",
586
+ "@angular/core": "^7",
587
+ "@angular/router": "^7",
588
+ "@angular/platform-browser": "^7",
589
+ "@angular/platform-browser-dynamic": "^7",
590
+ "core-js": "^3.15.2",
591
+ "rxjs": "^6.4",
592
+ "zone.js": "~0.9"
593
+ }
594
+ ```
595
+
596
+ ### Angular 8
597
+
598
+ In general, Angular 8 seems to work and is **supported**.
599
+
600
+ The basic dependencies look as follows:
601
+
602
+ ```json
603
+ {
604
+ "@angular/common": "^8",
605
+ "@angular/compiler": "^8",
606
+ "@angular/core": "^8",
607
+ "@angular/router": "^8",
608
+ "@angular/platform-browser": "^8",
609
+ "@angular/platform-browser-dynamic": "^8",
610
+ "core-js": "^3.15.2",
611
+ "rxjs": "^6.4",
612
+ "zone.js": "~0.9"
613
+ }
614
+ ```
615
+
616
+ ### Angular 9
617
+
618
+ In general, Angular 9 seems to work and is **supported**.
619
+
620
+ The basic dependencies look as follows:
621
+
622
+ ```json
623
+ {
624
+ "@angular/common": "^9",
625
+ "@angular/compiler": "^9",
626
+ "@angular/core": "^9",
627
+ "@angular/router": "^9",
628
+ "@angular/platform-browser": "^9",
629
+ "@angular/platform-browser-dynamic": "^9",
630
+ "core-js": "^3.15.2",
631
+ "rxjs": "~6.5",
632
+ "zone.js": "~0.9"
633
+ }
634
+ ```
635
+
636
+ ### Angular 10
637
+
638
+ In general, Angular 10 seems to work and is **supported**.
639
+
640
+ The basic dependencies look as follows:
641
+
642
+ ```json
643
+ {
644
+ "@angular/common": "^10",
645
+ "@angular/compiler": "^10",
646
+ "@angular/core": "^10",
647
+ "@angular/router": "^10",
648
+ "@angular/platform-browser": "^10",
649
+ "@angular/platform-browser-dynamic": "^10",
650
+ "core-js": "^3.15.2",
651
+ "rxjs": "~6.5",
652
+ "zone.js": "~0.9"
653
+ }
654
+ ```
655
+
656
+ ### Angular 11
657
+
658
+ In general, Angular 11 seems to work and is **supported**.
659
+
660
+ The basic dependencies look as follows:
661
+
662
+ ```json
663
+ {
664
+ "@angular/common": "^11",
665
+ "@angular/compiler": "^11",
666
+ "@angular/core": "^11",
667
+ "@angular/router": "^11",
668
+ "@angular/platform-browser": "^11",
669
+ "@angular/platform-browser-dynamic": "^11",
670
+ "core-js": "^3.15.2",
671
+ "rxjs": "~6.5",
672
+ "zone.js": "~0.9"
673
+ }
674
+ ```
675
+
676
+ ### Angular 12
677
+
678
+ In general, Angular 12 seems to work and is **supported**.
679
+
680
+ The basic dependencies look as follows:
681
+
682
+ ```json
683
+ {
684
+ "@angular/common": "^12",
685
+ "@angular/compiler": "^12",
686
+ "@angular/core": "^12",
687
+ "@angular/router": "^12",
688
+ "@angular/platform-browser": "^12",
689
+ "@angular/platform-browser-dynamic": "^12",
690
+ "core-js": "^3.15.2",
691
+ "rxjs": "~6.4",
692
+ "zone.js": "0.11.4"
693
+ }
694
+ ```
695
+
696
+ ### Angular 13
697
+
698
+ In general, Angular 13 seems to work and is **supported**.
699
+
700
+ The basic dependencies look as follows:
701
+
702
+ ```json
703
+ {
704
+ "@angular/common": "^13",
705
+ "@angular/compiler": "^13",
706
+ "@angular/core": "^13",
707
+ "@angular/router": "^13",
708
+ "@angular/platform-browser": "^13",
709
+ "@angular/platform-browser-dynamic": "^13",
710
+ "core-js": "^3.19.0",
711
+ "rxjs": "^7.4",
712
+ "zone.js": "0.11.4"
713
+ }
714
+ ```
715
+
716
+ Besides the usual imports the explicit import of the `@angular/compiler` package may be necessary.
717
+
718
+ So include in your app shell as preamble:
719
+
720
+ ```js
721
+ import 'core-js/proposals/reflect-metadata';
722
+ import '@angular/compiler';
723
+ ```
724
+
725
+ ### Angular 14
726
+
727
+ In general, Angular 14 seems to work and is **supported**.
728
+
729
+ The basic dependencies look as follows:
730
+
731
+ ```json
732
+ {
733
+ "@angular/common": "^14",
734
+ "@angular/compiler": "^14",
735
+ "@angular/core": "^14",
736
+ "@angular/router": "^14",
737
+ "@angular/platform-browser": "^14",
738
+ "@angular/platform-browser-dynamic": "^14",
739
+ "core-js": "^3.19.0",
740
+ "rxjs": "^7.4",
741
+ "zone.js": "~0.12.0"
742
+ }
743
+ ```
744
+
745
+ Besides the usual imports the explicit import of the `@angular/compiler` package may be necessary.
746
+
747
+ So include in your app shell as preamble:
748
+
749
+ ```js
750
+ import 'core-js/proposals/reflect-metadata';
751
+ import '@angular/compiler';
752
+ ```
753
+
754
+ ### Angular 15
755
+
756
+ In general, Angular 15 seems to work and is **supported**.
757
+
758
+ The basic dependencies look as follows:
759
+
760
+ ```json
761
+ {
762
+ "@angular/common": "^15",
763
+ "@angular/compiler": "^15",
764
+ "@angular/core": "^15",
765
+ "@angular/router": "^15",
766
+ "@angular/platform-browser": "^15",
767
+ "@angular/platform-browser-dynamic": "^15",
768
+ "core-js": "^3.19.0",
769
+ "rxjs": "^7.4",
770
+ "zone.js": "~0.13.0"
771
+ }
772
+ ```
773
+
774
+ Besides the usual imports the explicit import of the `@angular/compiler` package may be necessary.
775
+
776
+ So include in your app shell as preamble:
777
+
778
+ ```js
779
+ import 'core-js/proposals/reflect-metadata';
780
+ import '@angular/compiler';
781
+ ```
782
+
783
+ ### Angular 16
784
+
785
+ In general, Angular 16 seems to work and is **supported**.
786
+
787
+ The basic dependencies look as follows:
788
+
789
+ ```json
790
+ {
791
+ "@angular/common": "^16",
792
+ "@angular/compiler": "^16",
793
+ "@angular/core": "^16",
794
+ "@angular/router": "^16",
795
+ "@angular/platform-browser": "^16",
796
+ "@angular/platform-browser-dynamic": "^16",
797
+ "core-js": "^3.19.0",
798
+ "rxjs": "^7.4",
799
+ "zone.js": "~0.13.0"
800
+ }
801
+ ```
802
+
803
+ 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).
804
+
805
+ So include in your app shell as preamble:
806
+
807
+ ```js
808
+ import 'core-js/proposals/reflect-metadata';
809
+ import '@angular/compiler';
810
+ ```
811
+
153
812
  ## License
154
813
 
155
814
  Piral is released using the MIT license. For more information see the [license file](./LICENSE).