Note 1: If you want to follow the instructions below, make sure that you create a directory and are inside the directory
MkDir angular2-firststeps CD angular2-firststepsNote 2: You need to have Node and NPM installed to be able to run the following commands.
- Package.json
* What is it? A package.json file contains meta data about your app or module. Most importantly, it includes the list of dependencies to install from npm when running npm install.
* How to create it?npm init
Answer all the questions and it will create your package.json file.
If you look at the created package.json file, you will see that it only includes basic information, now it's time to add dependencies.
* How? by using
- typings.json
*What is it?
Many JavaScript libraries, such as jQuery, the Jasmine testing library, and Angular, extend the JavaScript environment with features and syntax that the TypeScript compiler doesn't recognize natively. When the compiler doesn't recognize something, it throws an error. The typescript definition (.d.ts) files are used to tell the compiler about these libraries that we load. Many libraries include definition files in their npm packages where both the TypeScript compiler and editors can find them. Angular is one such library so we don't need to add it's type definition file to our typings.json. This file is to list and install all the required typings for libraries without typings like jasmine.
*How to create it?
This command will create the empty file: (Note that we're using the typings tool which we installed as a dev dependency earlier)
typings init
and now to install different typing definitions:typings install dt~jasmine env~node --save --global
* Check here for more information on available options for the typings tool. - tsconfig.json *What is it? This file is to guide the compileras it generates the javascript files from the .ts files. check here for complete list and description of this file and available options.
npm install -s YOURPACKAGESnpm install will create a new directory called Node_modules and then it will download all the defined packages into this directory. the "-s" option makes sure that these package names are saved in package.json file. Below is the command to use for adding angular and it's requirement to your package:
npm install -S @angular/common @angular/compiler @angular/core @angular/platform-browser @angular/platform-browser-dynamic es6-shim reflect-metadata rxjs@5.0.0-beta.12 zone.jsRun the command and check your file structure as well as content of the package.json... magic :D Note that the above packages and dependencies may/will change in the future and you have to change for angular dependencies at the time when you are executing these commands. OK, so we have our basic dependencies added, now it's time to add the development dependencies. What are dev dependencies? These are packages that are required during the development like typescript or typings and won't be needed when the application is running (in production) How to add them? the --save-dev means that these packages should be added to dev dependencies.
npm install --save-dev typings typescript tslint</ br> Take a look at the scripts section of package.json file and have a play. We might go into details of that in another post.