Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit bb4ee33

Browse files
committed
docs(cookbook-aot-compiler): ward's tweaks to #2790
1 parent 66ab573 commit bb4ee33

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #docregion
2-
// main entry point
32
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3+
44
import { AppModule } from './app.module';
55

66
platformBrowserDynamic().bootstrapModule(AppModule);

public/docs/ts/latest/cookbook/aot-compiler.jade

+22-24
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ a#toh
343343

344344
***index.html***
345345

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+
347349
Here they are for comparison:
348350

349351
+makeTabs(
@@ -355,9 +357,6 @@ a#toh
355357
)
356358

357359
:marked
358-
They can't be in the same folder.
359-
***Put the AoT version in the `/aot` folder***.
360-
361360
The JiT version relies on `SystemJS` to load individual modules and requires the `reflect-metadata` shim.
362361
Both scripts appear in its `index.html`.
363362

@@ -366,8 +365,9 @@ a#toh
366365

367366
***main.ts***
368367

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:
371371

372372
+makeTabs(
373373
`toh-6/ts/app/main-aot.ts,
@@ -378,32 +378,26 @@ a#toh
378378
)
379379

380380
: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***
388382

389383
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.
392386

393387
While JiT app URLs are more flexible, stick with _component-relative_ URLs for compatibility with AoT compilation.
394388

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`.
396390
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:
398392
+makeExample('toh-6/ts/aot/index.html','moduleId')(format='.')
399393
.l-sub-section
400394
:marked
401395
Setting a global `module` is a temporary expedient.
402396
:marked
403-
*TypeScript configuration*
397+
***TypeScript configuration***
404398

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.
407401
AoT requires its own TypeScript configuration settings as well.
408402

409403
You'll need separate TypeScript configuration files such as these:
@@ -416,12 +410,16 @@ a#toh
416410
tsconfig.json (JiT)`
417411
)
418412

419-
.l-sub-section
413+
.callout.is-helpful
414+
header @Types and node modules
420415
: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/"`.
423419

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.
425423

426424
:marked
427425
### Tree Shaking

0 commit comments

Comments
 (0)