@@ -343,7 +343,9 @@ a#toh
343
343
344
344
***index.html***
345
345
346
- The JiT and AoT apps are setup and launched so differently that they require their own `index.html` files.
346
+ The JiT and AoT apps require their own `index.html` files because they setup and launch so differently.
347
+ **Put the AoT version in the `/aot` folder** because two `index.html` files can't be in the same folder.
348
+
347
349
Here they are for comparison:
348
350
349
351
+ makeTabs(
@@ -355,9 +357,6 @@ a#toh
355
357
)
356
358
357
359
:marked
358
- They can't be in the same folder.
359
- ***Put the AoT version in the `/aot` folder***.
360
-
361
360
The JiT version relies on `SystemJS` to load individual modules and requires the `reflect-metadata` shim.
362
361
Both scripts appear in its `index.html`.
363
362
@@ -366,8 +365,9 @@ a#toh
366
365
367
366
***main.ts***
368
367
369
- The JiT and AoT apps are also bootstraped differently that they require their own `main.ts` files.
370
- Here they are for comparison:
368
+ JiT and AoT applications boot in much the same way but require different Angular libraries to do so.
369
+ The key differences, covered in the [Bootstrap](#bootstrap) section above,
370
+ are evident in these `main` files which can and should reside in the same folder:
371
371
372
372
+ makeTabs(
373
373
` toh-6/ts/app/main-aot.ts,
@@ -378,32 +378,26 @@ a#toh
378
378
)
379
379
380
380
:marked
381
- They can and should exist in the same folder.
382
-
383
- The `app/main-aot.ts` file is used by the AoT config scripts (`tsconfig-aot.json` and `rollup-config.js`).
384
-
385
- Key differences are discussed in the [Bootstrap](#bootstrap) section, above.
386
-
387
- *Component-relative Template URLS*
381
+ ***Component-relative Template URLS***
388
382
389
383
The AoT compiler requires that `@Component` URLS for external templates and css files be _component-relative_.
390
- That means that the value of `@Component.templateUrl` is a URL value relative to the component class file:
391
- `foo .component.html` no matter where `foo .component.ts` sits in the project folder structure .
384
+ That means that the value of `@Component.templateUrl` is a URL value _relative_ to the component class file.
385
+ For example, a `'hero .component.html'` URL means that the template file is a sibling of its companion `hero .component.ts` file .
392
386
393
387
While JiT app URLs are more flexible, stick with _component-relative_ URLs for compatibility with AoT compilation.
394
388
395
- JiT-compiled apps, using the SystemJS loader and _component-relative_ URLs *must set the* `@Component.moduleId` *property to* `module.id`.
389
+ JiT-compiled applications that use the SystemJS loader and _component-relative_ URLs *must set the* `@Component.moduleId` *property to* `module.id`.
396
390
The `module` object is undefined when an AoT-compiled app runs.
397
- The app fails unless you assign a global `module` value in the `index.html` like this:
391
+ The app fails with a null reference error unless you assign a global `module` value in the `index.html` like this:
398
392
+ makeExample('toh-6/ts/aot/index.html' ,'moduleId' )( format ='.' )
399
393
.l-sub-section
400
394
:marked
401
395
Setting a global `module` is a temporary expedient.
402
396
:marked
403
- *TypeScript configuration*
397
+ *** TypeScript configuration** *
404
398
405
- JiT-compiled apps transpile to `commonjs` modules.
406
- AoT-compiled apps transpile to _ES2015_/_ES6_ modules to facilitate Tree Shaking.
399
+ JiT-compiled applications transpile to `commonjs` modules.
400
+ AoT-compiled applications transpile to _ES2015_/_ES6_ modules to facilitate Tree Shaking.
407
401
AoT requires its own TypeScript configuration settings as well.
408
402
409
403
You'll need separate TypeScript configuration files such as these:
@@ -416,12 +410,16 @@ a#toh
416
410
tsconfig.json (JiT)`
417
411
)
418
412
419
- .l-sub-section
413
+ .callout.is-helpful
414
+ header @Types and node modules
420
415
:marked
421
- _Note_ that the specific file structure of this project needs `typeRoots` to include `../../node_modules/@types/`,
422
- whereas in a typical setting it should include `node_modules/@types/` instead.
416
+ In the file structure of _this particular sample project_,
417
+ the `node_modules` folder happens to be two levels up from the project root.
418
+ Therefore, `"typeRoots"` must be set to `"../../node_modules/@types/"`.
423
419
424
- Make sure to edit accordingly to your project needs.
420
+ In a more typical project, `node_modules` would be a sibling of `tsconfig-aot.json`
421
+ and `"typeRoots"` would be set to `"node_modules/@types/"`.
422
+ Edit your `tsconfig-aot.json` to fit your project's file structure.
425
423
426
424
:marked
427
425
### Tree Shaking
0 commit comments