piral-ng 0.14.0-beta.3184 → 0.14.0-beta.3216

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.
package/README.md CHANGED
@@ -169,14 +169,6 @@ export class AngularPage {
169
169
  }
170
170
  ```
171
171
 
172
- ::: warning: Prefer not to use `templateUrl`
173
- 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).
174
-
175
- The same issue applies to `styleUrls`, which should be replaced by `styles`.
176
-
177
- If you still need to use `templateUrl` (or `styleUrls`) then take a look below at the Webpack config file.
178
- :::
179
-
180
172
  If you don't want to inline the `template` then just `require` the contents, e.g.,
181
173
 
182
174
  ```js
@@ -237,6 +229,7 @@ module.exports = (config) => {
237
229
  return config;
238
230
  };
239
231
  ```
232
+
240
233
  :::
241
234
 
242
235
  ::: summary: For Piral instance developers
@@ -319,6 +312,93 @@ export class SampleTileComponent {
319
312
  }
320
313
  ```
321
314
 
315
+ ## Converting an Angular Application to a Pilet
316
+
317
+ 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.
318
+
319
+ 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.
320
+
321
+ This is how your *webpack.config.js* can look like:
322
+
323
+ ```js
324
+ const extendWebpack = require('piral-ng/extend-webpack');
325
+
326
+ module.exports = extendWebpack({
327
+ ngOptions: {
328
+ jitMode: false,
329
+ },
330
+ });
331
+ ```
332
+
333
+ The available options are:
334
+
335
+ - `ngOptions` (providing input to the `AngularWebpackPlugin` class)
336
+ - `patterns` (providing input to the Webpack `copy-webpack-plugin`)
337
+ - `compilerOptions` (providing input to the `angularCompilerOptions` section of the *tsconfig.json*)
338
+
339
+ 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.
340
+
341
+ ::: failure: AoT does not work with dependency sharing
342
+ 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.
343
+ :::
344
+
345
+ 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:
346
+
347
+ ```ts
348
+ import { PiletApi } from '<your-app-shell>';
349
+
350
+ export function setup(api: PiletApi) {
351
+
352
+ }
353
+ ```
354
+
355
+ You can remove your *main.ts* (or similar) containing
356
+
357
+ ```ts
358
+ platformBrowserDynamic()
359
+ .bootstrapModule(AppModule)
360
+ .catch(err => console.error(err));
361
+ ```
362
+
363
+ as the bootstrapping is done by Piral. Instead, you now need to define your `AppModule` in the pilet:
364
+
365
+ ```ts
366
+ import { PiletApi } from '<your-app-shell>';
367
+ import { AppModule } from './app/AppModule.ts';
368
+
369
+ export function setup(api: PiletApi) {
370
+ api.defineNgModule(AppModule);
371
+ }
372
+ ```
373
+
374
+ Now you can register the exported components from the `AppModule` in the various parts. Example:
375
+
376
+ ```ts
377
+ import { PiletApi } from '<your-app-shell>';
378
+ import { AppModule } from './app/AppModule.ts';
379
+ import { AppComponent } from './app/AppComponent.ts';
380
+
381
+ export function setup(api: PiletApi) {
382
+ api.defineNgModule(AppModule);
383
+
384
+ api.registerPage('/foo/*', api.fromNg(AppComponent));
385
+ }
386
+ ```
387
+
388
+ 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.
389
+
390
+ 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/`).
391
+
392
+ 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.
393
+
394
+ ::: warning: Prefer not to use `templateUrl`
395
+ 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).
396
+
397
+ The same issue applies to `styleUrls`, which should be replaced by `styles`.
398
+
399
+ If you still need to use `templateUrl` (or `styleUrls`) then take a look below at the Webpack config file.
400
+ :::
401
+
322
402
  ## Angular Versions
323
403
 
324
404
  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`.
@@ -334,6 +414,7 @@ The basic dependencies look as follows:
334
414
  "@angular/common": "^2",
335
415
  "@angular/compiler": "^2",
336
416
  "@angular/core": "^2",
417
+ "@angular/router": "^2",
337
418
  "@angular/platform-browser": "^2",
338
419
  "@angular/platform-browser-dynamic": "^2",
339
420
  "core-js": "^3.15.2",
@@ -357,6 +438,7 @@ The basic dependencies look as follows:
357
438
  "@angular/common": "^4",
358
439
  "@angular/compiler": "^4",
359
440
  "@angular/core": "^4",
441
+ "@angular/router": "^4",
360
442
  "@angular/platform-browser": "^4",
361
443
  "@angular/platform-browser-dynamic": "^4",
362
444
  "core-js": "^3.15.2",
@@ -373,11 +455,12 @@ The basic dependencies look as follows:
373
455
 
374
456
  ```json
375
457
  {
376
- "@angular/common": "^4",
377
- "@angular/compiler": "^4",
378
- "@angular/core": "^4",
379
- "@angular/platform-browser": "^4",
380
- "@angular/platform-browser-dynamic": "^4",
458
+ "@angular/common": "^5",
459
+ "@angular/compiler": "^5",
460
+ "@angular/core": "^5",
461
+ "@angular/router": "^5",
462
+ "@angular/platform-browser": "^5",
463
+ "@angular/platform-browser-dynamic": "^5",
381
464
  "core-js": "^3.15.2",
382
465
  "rxjs": "^5.0.0",
383
466
  "zone.js": "~0.9"
@@ -395,6 +478,7 @@ The basic dependencies look as follows:
395
478
  "@angular/common": "^6",
396
479
  "@angular/compiler": "^6",
397
480
  "@angular/core": "^6",
481
+ "@angular/router": "^6",
398
482
  "@angular/platform-browser": "^6",
399
483
  "@angular/platform-browser-dynamic": "^6",
400
484
  "core-js": "^3.15.2",
@@ -411,11 +495,12 @@ The basic dependencies look as follows:
411
495
 
412
496
  ```json
413
497
  {
414
- "@angular/common": "^6",
415
- "@angular/compiler": "^6",
416
- "@angular/core": "^6",
417
- "@angular/platform-browser": "^6",
418
- "@angular/platform-browser-dynamic": "^6",
498
+ "@angular/common": "^7",
499
+ "@angular/compiler": "^7",
500
+ "@angular/core": "^7",
501
+ "@angular/router": "^7",
502
+ "@angular/platform-browser": "^7",
503
+ "@angular/platform-browser-dynamic": "^7",
419
504
  "core-js": "^3.15.2",
420
505
  "rxjs": "^6.0.0",
421
506
  "zone.js": "~0.9"
@@ -433,6 +518,7 @@ The basic dependencies look as follows:
433
518
  "@angular/common": "^8",
434
519
  "@angular/compiler": "^8",
435
520
  "@angular/core": "^8",
521
+ "@angular/router": "^8",
436
522
  "@angular/platform-browser": "^8",
437
523
  "@angular/platform-browser-dynamic": "^8",
438
524
  "core-js": "^3.15.2",
@@ -452,6 +538,7 @@ The basic dependencies look as follows:
452
538
  "@angular/common": "^9",
453
539
  "@angular/compiler": "^9",
454
540
  "@angular/core": "^9",
541
+ "@angular/router": "^9",
455
542
  "@angular/platform-browser": "^9",
456
543
  "@angular/platform-browser-dynamic": "^9",
457
544
  "core-js": "^3.15.2",
@@ -471,6 +558,7 @@ The basic dependencies look as follows:
471
558
  "@angular/common": "^10",
472
559
  "@angular/compiler": "^10",
473
560
  "@angular/core": "^10",
561
+ "@angular/router": "^10",
474
562
  "@angular/platform-browser": "^10",
475
563
  "@angular/platform-browser-dynamic": "^10",
476
564
  "core-js": "^3.15.2",
@@ -490,6 +578,7 @@ The basic dependencies look as follows:
490
578
  "@angular/common": "^11",
491
579
  "@angular/compiler": "^11",
492
580
  "@angular/core": "^11",
581
+ "@angular/router": "^11",
493
582
  "@angular/platform-browser": "^11",
494
583
  "@angular/platform-browser-dynamic": "^11",
495
584
  "core-js": "^3.15.2",
@@ -509,6 +598,7 @@ The basic dependencies look as follows:
509
598
  "@angular/common": "^12",
510
599
  "@angular/compiler": "^12",
511
600
  "@angular/core": "^12",
601
+ "@angular/router": "^12",
512
602
  "@angular/platform-browser": "^12",
513
603
  "@angular/platform-browser-dynamic": "^12",
514
604
  "core-js": "^3.15.2",
@@ -0,0 +1,67 @@
1
+ const { AngularWebpackPlugin } = require('@ngtools/webpack');
2
+ const CopyPlugin = require('copy-webpack-plugin');
3
+ const { resolve } = require('path');
4
+
5
+ const ngtoolsLoader = require.resolve('@ngtools/webpack');
6
+ const toStringLoader = require.resolve('to-string-loader');
7
+ const cssLoader = require.resolve('css-loader');
8
+ const sassLoader = require.resolve('sass-loader');
9
+
10
+ module.exports =
11
+ (options = {}) =>
12
+ (config) => {
13
+ const {
14
+ patterns = [{ from: resolve(process.cwd(), 'src/assets') }],
15
+ ngOptions = {},
16
+ compilerOptions = {},
17
+ } = options;
18
+ const cssLoaderNoModule = `${cssLoader}?esModule=false`;
19
+
20
+ config.module.rules
21
+ .filter((m) => m.test.toString() === /\.css$/i.toString())
22
+ .forEach((m) => {
23
+ m.exclude = /\.component.css$/i;
24
+ });
25
+
26
+ config.module.rules
27
+ .filter((m) => m.test.toString() === /\.s[ac]ss$/i.toString())
28
+ .forEach((m) => {
29
+ m.exclude = /\.component.s[ac]ss$/i;
30
+ });
31
+
32
+ const ruleIndex = config.module.rules.findIndex((m) => m.test.toString() === /\.tsx?$/i.toString());
33
+
34
+ config.module.rules.splice(
35
+ ruleIndex,
36
+ 1,
37
+ {
38
+ test: /\.[jt]sx?$/,
39
+ loader: ngtoolsLoader,
40
+ },
41
+ {
42
+ test: /\.component.css$/i,
43
+ use: [toStringLoader, cssLoaderNoModule],
44
+ },
45
+ {
46
+ test: /\.component.s[ac]ss$/i,
47
+ use: [toStringLoader, cssLoaderNoModule, sassLoader],
48
+ },
49
+ );
50
+
51
+ config.plugins.push(
52
+ new AngularWebpackPlugin({
53
+ tsconfig: resolve(process.cwd(), 'tsconfig.json'),
54
+ jitMode: true,
55
+ ...ngOptions,
56
+ compilerOptions: {
57
+ ...compilerOptions,
58
+ compilationMode: 'partial',
59
+ },
60
+ }),
61
+ new CopyPlugin({
62
+ patterns,
63
+ }),
64
+ );
65
+
66
+ return config;
67
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-ng",
3
- "version": "0.14.0-beta.3184",
3
+ "version": "0.14.0-beta.3216",
4
4
  "description": "Plugin for integrating Angular components in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -27,7 +27,8 @@
27
27
  "common.d.ts",
28
28
  "common.js",
29
29
  "convert.d.ts",
30
- "convert.js"
30
+ "convert.js",
31
+ "extend-webpack.js"
31
32
  ],
32
33
  "repository": {
33
34
  "type": "git",
@@ -51,7 +52,7 @@
51
52
  "@angular/platform-browser": "^8.0.0",
52
53
  "@angular/platform-browser-dynamic": "^8.0.0",
53
54
  "@angular/router": "^8.0.0",
54
- "piral-core": "^0.14.0-beta.3184",
55
+ "piral-core": "0.14.0-beta.3216",
55
56
  "rxjs": "^7.3.0"
56
57
  },
57
58
  "peerDependencies": {
@@ -65,5 +66,5 @@
65
66
  "rxjs": "^5.0.0 || ^6.0.0 || ^7.0.0",
66
67
  "zone.js": "~0.9.0 || ~0.10.0 || ~0.11.0"
67
68
  },
68
- "gitHead": "2d00bfdcdf47c737ffb8d58f700945362ab9ac6d"
69
+ "gitHead": "4ae646f90377893373f4ebc575eb0b8a707f8b94"
69
70
  }