Setting up an Angular project in WebStorm
Assuming that you installed WebStorm, fire the IDE and check out a new project from a Git repository.
Now, set the repository URL to https://github.com/angular/angular2-seed.git and save the project in a folder called the sherlock project
, as shown:
Click on the Clone button and open the project in WebStorm. Next, click on the packages.json
file and observe the dependencies. As you can see, this is a very lean seed with minimal configurations. It contains the Angular release candidate 2, plus the required modules to get the project up and running.
As you see in the following screenshot, apart from main Angular modules, we have the rxjs
library, which is the Reactive eXtension for JS and we will use it for transforming, composing, and querying streams of data.
The first thing we need to do is install all the required dependencies defined inside the package.json
file. Right-click on the file and select the run npm install
option.
Tip
Please note installing packages using right-click and choosing the installation command is valid inside the IDE only. If you prefer to use the command line, simply use the following command:
$ npm install
Installing the packages for the first time will take a while. In the meantime, explore the devDependencies
section of package.json
in the editor. As you see, we have all the required bells and whistles to run the project, including TypeScript and web server to start the development:
"devDependencies": { "awesome-typescript-loader": "~0.16.2", "es6-promise": "3.0.2", "es6-shim": "0.35.0", "reflect-metadata": "0.1.2", "source-map-loader": "^0.1.5", "typescript": "~1.8.9", "typings": "~1.0.3", "webpack": "^1.12.9", "webpack-dev-server": "^1.14.0", "webpack-merge": "^0.8.4" },
We also have some nifty scripts defined inside package.json
that automate useful processes. For example, to start a web server and see the seed in action, we can simply execute the following command in a terminal. (These scripts are shipped with the seed project and they are located inside the package.json
file, under the script
property. There is nothing special about them, they are just simple npm commands and you are more than welcome to add your commands if you like):
$ npm run server
Alternatively, we can right-click on the package.json
file and select Show npm Scripts. This will open another side tab in WebStorm and show all the available scripts inside the current file:
Double-click on the start script and it will run the web server and load the seed application on port 3000
. This means that if you visit
http://localhost:3000
, you will see the seed application in your browser, as illustrated:
Tip
If you are wondering where the port number comes from, look into the package.json
file and examine the server key under the scripts
section:
"server": "webpack-dev-server --inline --colors --progress --display-error-details --display-cached --port 3000 --content-base src"
There is one more thing before we move on to the next topic. If you open any .ts
file, WebStorm will ask you if you want it to transpile the code to JavaScript. If you say no
once, it will never show up again.
In the following screenshot, below the tabs we can see the question (Compile TypeScript to JavaScript?) and possible answers (OK, No, Configure):
Choose No because we don't need WebStorm to transpile for us because the start script already contains a transpiler that takes care of all the transformations for us.