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

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
@@ -237,6 +237,7 @@ module.exports = (config) => {
237
237
  return config;
238
238
  };
239
239
  ```
240
+
240
241
  :::
241
242
 
242
243
  ::: summary: For Piral instance developers
@@ -319,6 +320,79 @@ export class SampleTileComponent {
319
320
  }
320
321
  ```
321
322
 
323
+ ## Converting an Angular Application to a Pilet
324
+
325
+ 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.
326
+
327
+ 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.
328
+
329
+ This is how your *webpack.config.js* can look like:
330
+
331
+ ```js
332
+ const extendWebpack = require('piral-ng/extend-webpack');
333
+
334
+ module.exports = extendWebpack({
335
+ ngOptions: {
336
+ jitMode: false,
337
+ },
338
+ });
339
+ ```
340
+
341
+ The available options are:
342
+
343
+ - `ngOptions` (providing input to the `AngularWebpackPlugin` class)
344
+ - `patterns` (providing input to the Webpack `copy-webpack-plugin`)
345
+ - `compilerOptions` (providing input to the `angularCompilerOptions` section of the *tsconfig.json*)
346
+
347
+ 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.
348
+
349
+ 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:
350
+
351
+ ```ts
352
+ import { PiletApi } from '<your-app-shell>';
353
+
354
+ export function setup(api: PiletApi) {
355
+
356
+ }
357
+ ```
358
+
359
+ You can remove your *main.ts* (or similar) containing
360
+
361
+ ```ts
362
+ platformBrowserDynamic()
363
+ .bootstrapModule(AppModule)
364
+ .catch(err => console.error(err));
365
+ ```
366
+
367
+ as the bootstrapping is done by Piral. Instead, you now need to define your `AppModule` in the pilet:
368
+
369
+ ```ts
370
+ import { PiletApi } from '<your-app-shell>';
371
+ import { AppModule } from './app/AppModule.ts';
372
+
373
+ export function setup(api: PiletApi) {
374
+ api.defineNgModule(AppModule);
375
+ }
376
+ ```
377
+
378
+ Now you can register the exported components from the `AppModule` in the various parts. Example:
379
+
380
+ ```ts
381
+ import { PiletApi } from '<your-app-shell>';
382
+ import { AppModule } from './app/AppModule.ts';
383
+ import { AppComponent } from './app/AppComponent.ts';
384
+
385
+ export function setup(api: PiletApi) {
386
+ api.defineNgModule(AppModule);
387
+
388
+ api.registerPage('/foo/*', api.fromNg(AppComponent));
389
+ }
390
+ ```
391
+
392
+ 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.
393
+
394
+ 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/`).
395
+
322
396
  ## Angular Versions
323
397
 
324
398
  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 +408,7 @@ The basic dependencies look as follows:
334
408
  "@angular/common": "^2",
335
409
  "@angular/compiler": "^2",
336
410
  "@angular/core": "^2",
411
+ "@angular/router": "^2",
337
412
  "@angular/platform-browser": "^2",
338
413
  "@angular/platform-browser-dynamic": "^2",
339
414
  "core-js": "^3.15.2",
@@ -357,6 +432,7 @@ The basic dependencies look as follows:
357
432
  "@angular/common": "^4",
358
433
  "@angular/compiler": "^4",
359
434
  "@angular/core": "^4",
435
+ "@angular/router": "^4",
360
436
  "@angular/platform-browser": "^4",
361
437
  "@angular/platform-browser-dynamic": "^4",
362
438
  "core-js": "^3.15.2",
@@ -373,11 +449,12 @@ The basic dependencies look as follows:
373
449
 
374
450
  ```json
375
451
  {
376
- "@angular/common": "^4",
377
- "@angular/compiler": "^4",
378
- "@angular/core": "^4",
379
- "@angular/platform-browser": "^4",
380
- "@angular/platform-browser-dynamic": "^4",
452
+ "@angular/common": "^5",
453
+ "@angular/compiler": "^5",
454
+ "@angular/core": "^5",
455
+ "@angular/router": "^5",
456
+ "@angular/platform-browser": "^5",
457
+ "@angular/platform-browser-dynamic": "^5",
381
458
  "core-js": "^3.15.2",
382
459
  "rxjs": "^5.0.0",
383
460
  "zone.js": "~0.9"
@@ -395,6 +472,7 @@ The basic dependencies look as follows:
395
472
  "@angular/common": "^6",
396
473
  "@angular/compiler": "^6",
397
474
  "@angular/core": "^6",
475
+ "@angular/router": "^6",
398
476
  "@angular/platform-browser": "^6",
399
477
  "@angular/platform-browser-dynamic": "^6",
400
478
  "core-js": "^3.15.2",
@@ -411,11 +489,12 @@ The basic dependencies look as follows:
411
489
 
412
490
  ```json
413
491
  {
414
- "@angular/common": "^6",
415
- "@angular/compiler": "^6",
416
- "@angular/core": "^6",
417
- "@angular/platform-browser": "^6",
418
- "@angular/platform-browser-dynamic": "^6",
492
+ "@angular/common": "^7",
493
+ "@angular/compiler": "^7",
494
+ "@angular/core": "^7",
495
+ "@angular/router": "^7",
496
+ "@angular/platform-browser": "^7",
497
+ "@angular/platform-browser-dynamic": "^7",
419
498
  "core-js": "^3.15.2",
420
499
  "rxjs": "^6.0.0",
421
500
  "zone.js": "~0.9"
@@ -433,6 +512,7 @@ The basic dependencies look as follows:
433
512
  "@angular/common": "^8",
434
513
  "@angular/compiler": "^8",
435
514
  "@angular/core": "^8",
515
+ "@angular/router": "^8",
436
516
  "@angular/platform-browser": "^8",
437
517
  "@angular/platform-browser-dynamic": "^8",
438
518
  "core-js": "^3.15.2",
@@ -452,6 +532,7 @@ The basic dependencies look as follows:
452
532
  "@angular/common": "^9",
453
533
  "@angular/compiler": "^9",
454
534
  "@angular/core": "^9",
535
+ "@angular/router": "^9",
455
536
  "@angular/platform-browser": "^9",
456
537
  "@angular/platform-browser-dynamic": "^9",
457
538
  "core-js": "^3.15.2",
@@ -471,6 +552,7 @@ The basic dependencies look as follows:
471
552
  "@angular/common": "^10",
472
553
  "@angular/compiler": "^10",
473
554
  "@angular/core": "^10",
555
+ "@angular/router": "^10",
474
556
  "@angular/platform-browser": "^10",
475
557
  "@angular/platform-browser-dynamic": "^10",
476
558
  "core-js": "^3.15.2",
@@ -490,6 +572,7 @@ The basic dependencies look as follows:
490
572
  "@angular/common": "^11",
491
573
  "@angular/compiler": "^11",
492
574
  "@angular/core": "^11",
575
+ "@angular/router": "^11",
493
576
  "@angular/platform-browser": "^11",
494
577
  "@angular/platform-browser-dynamic": "^11",
495
578
  "core-js": "^3.15.2",
@@ -509,6 +592,7 @@ The basic dependencies look as follows:
509
592
  "@angular/common": "^12",
510
593
  "@angular/compiler": "^12",
511
594
  "@angular/core": "^12",
595
+ "@angular/router": "^12",
512
596
  "@angular/platform-browser": "^12",
513
597
  "@angular/platform-browser-dynamic": "^12",
514
598
  "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.3187",
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.3187",
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": "8c7afcbb45ab9fcb2dde5d8377416ff3bc86d3c8"
69
70
  }