|
| 1 | +# Angular CLI |
| 2 | + |
| 3 | +### Overview |
| 4 | +The Angular CLI is a tool to initialize, develop, scaffold and maintain [Angular](https://angular.io) applications |
| 5 | + |
| 6 | +### Getting Started |
| 7 | +To install the angular-cli: |
| 8 | +``` |
| 9 | +npm install -g angular-cli |
| 10 | +``` |
| 11 | + |
| 12 | +Generating and serving an Angular project via a development server |
| 13 | +[Create](new) and [run](serve) a new project: |
| 14 | +``` |
| 15 | +ng new my-project |
| 16 | +cd new-project |
| 17 | +ng serve |
| 18 | +``` |
| 19 | +Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files. |
| 20 | + |
| 21 | +### Build Targets and Environment Files |
| 22 | + |
| 23 | +`ng build` can specify both a build target (`--target=production` or `--target=development`) and an |
| 24 | +environment file to be used with that build (`--environment=dev` or `--environment=prod`). |
| 25 | +By default, the development build target and environment are used. |
| 26 | + |
| 27 | +The mapping used to determine which environment file is used can be found in `angular-cli.json`: |
| 28 | + |
| 29 | +```json |
| 30 | +"environments": { |
| 31 | + "source": "environments/environment.ts", |
| 32 | + "dev": "environments/environment.ts", |
| 33 | + "prod": "environments/environment.prod.ts" |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +These options also apply to the serve command. If you do not pass a value for `environment`, |
| 38 | +it will default to `dev` for `development` and `prod` for `production`. |
| 39 | + |
| 40 | +### Bundling |
| 41 | + |
| 42 | +All builds make use of bundling, and using the `--prod` flag in `ng build --prod` |
| 43 | +or `ng serve --prod` will also make use of uglifying and tree-shaking functionality. |
| 44 | + |
| 45 | +### Running unit tests |
| 46 | + |
| 47 | +```bash |
| 48 | +ng test |
| 49 | +``` |
| 50 | + |
| 51 | +Tests will execute after a build is executed via [Karma](http://karma-runner.github.io/0.13/index.html), and it will automatically watch your files for changes. You can run tests a single time via `--watch=false` or `--single-run`. |
| 52 | + |
| 53 | +### Running end-to-end tests |
| 54 | + |
| 55 | +```bash |
| 56 | +ng e2e |
| 57 | +``` |
| 58 | + |
| 59 | +Before running the tests make sure you are serving the app via `ng serve`. |
| 60 | +End-to-end tests are run via [Protractor](https://angular.github.io/protractor/). |
| 61 | + |
| 62 | +### Global styles |
| 63 | + |
| 64 | +The `styles.css` file allows users to add global styles and supports |
| 65 | +[CSS imports](https://developer.mozilla.org/en/docs/Web/CSS/@import). |
| 66 | + |
| 67 | +If the project is created with the `--style=sass` option, this will be a `.sass` |
| 68 | +file instead, and the same applies to `scss/less/styl`. |
| 69 | + |
| 70 | +You can add more global styles via the `apps[0].styles` property in `angular-cli.json`. |
| 71 | + |
| 72 | +### Global Library Installation |
| 73 | + |
| 74 | +Some javascript libraries need to be added to the global scope, and loaded as if |
| 75 | +they were in a script tag. We can do this using the `apps[0].scripts` and |
| 76 | +`apps[0].styles` properties of `angular-cli.json`. |
| 77 | + |
| 78 | +As an example, to use [Bootstrap 4](http://v4-alpha.getbootstrap.com/) this is |
| 79 | +what you need to do: |
| 80 | + |
| 81 | +First install Bootstrap from `npm`: |
| 82 | + |
| 83 | +```bash |
| 84 | +npm install bootstrap@next |
| 85 | +``` |
| 86 | + |
| 87 | +Then add the needed script files to `apps[0].scripts`: |
| 88 | + |
| 89 | +```json |
| 90 | +"scripts": [ |
| 91 | + "../node_modules/jquery/dist/jquery.js", |
| 92 | + "../node_modules/tether/dist/js/tether.js", |
| 93 | + "../node_modules/bootstrap/dist/js/bootstrap.js" |
| 94 | +], |
| 95 | +``` |
| 96 | + |
| 97 | +Finally add the Bootstrap CSS to the `apps[0].styles` array: |
| 98 | +```json |
| 99 | +"styles": [ |
| 100 | + "../node_modules/bootstrap/dist/css/bootstrap.css", |
| 101 | + "styles.css" |
| 102 | +], |
| 103 | +``` |
| 104 | + |
| 105 | +Restart `ng serve` if you're running it, and Bootstrap 4 should be working on |
| 106 | +your app. |
| 107 | + |
| 108 | +### Additional Commands |
| 109 | +* [ng new](new) |
| 110 | +* [ng init](init) |
| 111 | +* [ng serve](serve) |
| 112 | +* [ng generate](generate) |
| 113 | +* [ng test](test) |
| 114 | +* [ng e2e](e2e) |
| 115 | +* [ng build](build) |
| 116 | +* [ng get/ng set](config) |
| 117 | +* [ng docs](docs) |
| 118 | + |
| 119 | +### How to Guides |
| 120 | +* Setup AngularFire _(coming soon)_ |
| 121 | +* Include bootstrap (CSS) _(coming soon)_ |
| 122 | +* Include Font Awesome _(coming soon)_ |
| 123 | +* Setup of global styles _(coming soon)_ |
| 124 | +* Setup bootstrap with SASS _(coming soon)_ |
| 125 | +* Setup Angular Material 2 _(coming soon)_ |
0 commit comments