Angular-cli
Here you will find how to start with angular-cli , generating new component/service/pipe/module with angular-cli , add 3 party like bootstrap , build angular project.
Create empty Angular2 application with angular-cli
Section titled “Create empty Angular2 application with angular-cli”Requirements:
- NodeJS : Download page
- npm or yarn
Run the following commands with cmd from new directory folder:
npm install -g @angular/clioryarn global add @angular/cling new PROJECT_NAMEcd PROJECT_NAMEng serve
Open your browser at localhost:4200
Generating Components, Directives, Pipes and Services
Section titled “Generating Components, Directives, Pipes and Services”just use your cmd: You can use the ng generate (or just ng g) command to generate Angular components:
- Component:
ng g component my-new-component - Directive:
ng g directive my-new-directive - Pipe:
ng g pipe my-new-pipe - Service:
ng g service my-new-service - Class:
ng g class my-new-classt - Interface:
ng g interface my-new-interface - Enum:
ng g enum my-new-enum - Module:
ng g module my-module
Adding 3rd party libs
Section titled “Adding 3rd party libs”In angular-cli.json you can change the app configuration.
If you want to add ng2-bootstrap for example:
"scripts": [ "../node_modules/jquery/dist/jquery.js", "../node_modules/bootstrap/dist/js/bootstrap.js" ]build with angular-cli
Section titled “build with angular-cli”In angular-cli.json at outDir key you can define your build directory;
these are equivalent
ng build --target=production --environment=prodng build --prod --env=prodng build --prodand so are these
ng build --target=development --environment=devng build --dev --e=devng build --devng buildWhen building you can modify base tag () in your index.html with —base-href your-url option.
Sets base tag href to /myUrl/ in your index.html
ng build --base-href /myUrl/ng build --bh /myUrl/New project with scss/sass as stylesheet
Section titled “New project with scss/sass as stylesheet”The default style files generated and compiled by @angular/cli are css.
If you want to use scss instead, generate your project with:
ng new project_name --style=scssIf you want to use sass, generate your project with:
ng new project_name --style=sassSet yarn as default package manager for @angular/cli
Section titled “Set yarn as default package manager for @angular/cli”Yarn is an alternative for npm, the default package manager on @angular/cli. If you want to use yarn as package manager for @angular/cli follow this steps:
Requirements
Section titled “Requirements”- yarn (
npm install --global yarnor see the installation page) - @angular/cli (
npm install -g @angular/clioryarn global add @angular/cli)
To set yarn as @angular/cli package manager:
ng set --global packageManager=yarn
To set back npm as @angular/cli package manager:
ng set --global packageManager=npm