@@ -41,7 +41,7 @@ include ../../../../_includes/_util-fns
41
41
42
42
:markdown
43
43
We've just defined an Angular 2 **component**,
44
- one of the most important beasts in the Angular zoo .
44
+ one of the most important Angular 2 features .
45
45
Components are our primary means of creating application views
46
46
and supporting them with application logic.
47
47
@@ -231,71 +231,51 @@ include ../../../../_includes/_util-fns
231
231
.l-main-section
232
232
233
233
:markdown
234
- ## Install tools and application packages
234
+ ## Install npm packages locally
235
235
236
- We'll need a set of tools for our application development throughout this guide.
237
- We've already installed **`live-server`**. Let's install two more:
238
-
239
- - the **TypeScript compiler**
236
+ We'll replace the web-based scripts in our `index.html` with
237
+ scripts resident on our local machine.
238
+ We get those scripts by installing two runtime `npm` packages into our project.
240
239
240
+ >**angular.js** - the Angular 2 library.
241
241
242
- - the [**tsd package manager**](https://www.npmjs.com/package/tsd "TSD Package Manager") so we can access
243
- [TypeScript type definition files](http://definitelytyped.org/ "Definitely Typed").
242
+ >**system.js** - an open-source library that provides module loading.
244
243
245
- **Open** a terminal window and issue the following `npm` command to install both packages globally :
244
+ We'll also install three development tools :
246
245
247
- pre.prettyprint.lang-bash
248
- code npm install -g typescript tsd
246
+ >**typescript** - the TypeScript compiler
249
247
250
- .l-sub-section
251
- :markdown
252
- Now might be a good time to ensure that we're installing Angular-compatible versions of our tools.
253
- Issue the following commands in that same terminal window to confirm that we have the appropriate versions:
254
- table
255
- tr
256
- th Command
257
- th Versions
258
- tr
259
- td
260
- code node -v
261
- td 0.10.* - 0.12.* & nbsp& nbspBut not 4.0.0 !!!
262
- tr
263
- td
264
- code npm -v
265
- td 2.11+ (3.* is fine)
266
- tr
267
- td
268
- code tsc -v
269
- td 1.6+
270
- tr
271
- td
272
- code tsd --version
273
- td 0.6.5+
274
- tr
275
- td
276
- code live-server -v
277
- td 0.8+
278
-
279
- :markdown
280
- ### Install local packages
281
-
282
- We'll replace the web-based scripts in our `index.html` with
283
- scripts resident on our local machine. We get those scripts by installing two `npm` packages into our project.
248
+ >**tsd** - the [tsd package manager](https://www.npmjs.com/package/tsd "TSD Package Manager") so we can access
249
+ [TypeScript type definition files](http://definitelytyped.org/ "Definitely Typed")
284
250
285
- >***angular.js***, the Angular 2 library.
251
+ >**[live-server](https://www.npmjs.com/package/live-server "Live-server")** - the static file server that reloads the browser when files change.
252
+ We may have loaded it earlier. We're doing it again
253
+ locally in our project so we are no longer vulnerable to
254
+ a global uninstall or version change.
286
255
287
- >***system.js***, an open-source library that provides module loading.
256
+ **Open** a terminal window at our application's **root folder**
288
257
289
- In a terminal window at our application's **root folder** type :
258
+ Enter these commands :
290
259
```
291
260
npm init -y
292
261
262
+ npm i typescript tsd live-server --save-dev
293
263
```
294
264
295
265
These commands both *install* the packages and *create* an npm `package.json` that will
296
266
help us develop and maintain our application in future.
297
267
The essence of our `package.json` should look like this:
298
- + makeJson('gettingstarted/ts/package.json' , { paths: ' name, version, dependencies ' })
268
+
269
+ + makeJson('gettingstarted/ts/package.json' , { paths: ' name, version, dependencies, devDependencies' })
270
+
271
+ :markdown
272
+ There is also a `scripts` section. **Find and replace** it with the following:
273
+
274
+ + makeJson('gettingstarted/ts/package.json' , { paths: ' scripts' })
275
+
276
+ :markdown
277
+ We've just extended our project world with script commands
278
+ that we'll be running very soon.
299
279
300
280
.l-main-section
301
281
:markdown
@@ -354,14 +334,15 @@ include ../../../../_includes/_util-fns
354
334
that holds links to the type definition files in those packages.
355
335
356
336
In the ***root* folder** enter the following command
337
+ (one of the `npm` scripts we added a short while ago)
357
338
358
339
pre.prettyprint.lang-bash
359
- code tsd link --config src/ tsd.json
340
+ code npm run tsd
360
341
361
342
:markdown
362
343
That produces a new **`src/typings`** folder with the **`tsd.d.ts`** file.
363
344
364
- Now Angular type checking and intellisense lights up automatically as we write our app
345
+ Now type- checking and intellisense light up automatically as we write our app
365
346
in the Visual Studio Code and Web Storm editors. Check your editor's documentation for
366
347
instructions on using the `tsd.d.ts` file.
367
348
@@ -393,49 +374,56 @@ include ../../../../_includes/_util-fns
393
374
:markdown
394
375
## Compile the TypeScript to JavaScript
395
376
396
- We are no longer transpiling TypeScript to JavaScript in the browser.
397
- We're compiling it on our machine instead.
377
+ We no longer transpile TypeScript to JavaScript in the browser.
378
+ We run the **T**ype**S**cript **C**ompiler (TSC) on our machine instead.
398
379
399
- Open a terminal window in the **root of the application folder** (not *src*) and enter:
380
+ Open a terminal window in the **root of the application folder** and enter:
400
381
401
382
pre.prettyprint.lang-bash
402
- code tsc -p src -w
383
+ code npm run tsc
403
384
404
385
:markdown
405
- After it runs we should find the generated *app.js* file in the *src* folder and also an *app.map.js* file that
386
+ When it's done we should find the generated *app.js* file in the *src* folder and also an *app.map.js* file that
406
387
helps debuggers navigate between the JavaScript and the TypeScript source.
407
388
408
- We gave *tsc* the watch option (`-w`). It will watch for changes to our *.ts* files and
409
- recompile them automatically. Leave it running in this terminal window.
389
+ Our script set the compiler watch option (`-w`) so the
390
+ compiler stays alive when it's finished.
391
+ It watches for changes to our **`.ts`** files
392
+ and recompiles them automatically.
393
+
394
+ Leave this command running in the terminal window.
395
+ You can stop it anytime with `Ctrl-C`.
410
396
411
397
.l-main-section
412
398
:markdown
413
399
## Run the app!
414
400
415
- Now we are ready to see this app in action.
401
+ Now we are ready to see our app in action.
416
402
417
- Open another terminal window in the **root of the application folder** (not *src*) and
418
- launch `live-server` again although this time we add command line
419
- arguments telling it to **serve from the application's new location in `src`** :
403
+ Open another terminal window in the **root of the application folder** and
404
+ launch `live-server` again although this time we'll do it with
405
+ one of our `npm` script commands :
420
406
421
407
pre.prettyprint.lang-bash
422
- code live-server --open=src
408
+ code npm start
423
409
424
410
:markdown
425
- **live-server** loads the browser for us, serves the HTML and JavaScript files, and we should see it display our
426
- application message once more:
411
+ **live-server** loads the browser for us, serves the HTML and JavaScript files,
412
+ and displays our application message once more:
427
413
428
414
figure.image-display
429
415
img( src ='/resources/images/devguide/getting-started/my-first-app.png' alt ="Output of getting started app" )
430
416
431
417
:markdown
432
418
### Make some changes
433
- **live-server** detects changes to our files and refreshes the browser page for us automatically.
419
+ **` live-server` ** detects changes to our files and refreshes the browser page for us automatically.
434
420
435
421
Try changing the message to "My SECOND Angular 2 app".
436
422
437
- The TypeScript compiler running in the first terminal window is watching our source code. It recompiles and produces
438
- the revised *app.js*. The *live-server* sees that change and reloads the browser.
423
+ The TypeScript compiler in the first terminal window is watching our source code. It recompiles and produces
424
+ the revised *app.js*. The `live-server` sees that change and reloads the browser.
425
+
426
+ Keep `live-server` running in this terminal window. You can stop it anytime with `Ctrl-C`.
439
427
440
428
.l-main-section
441
429
:markdown
0 commit comments