본문 바로가기

Frontend/Angular

Angular - CLI

반응형
Angular CLI is a command line interface that provides a better way to create and manage Angular projects.

CLI Installation

npm install -g @angular/cli

CLI Update

npm uninstall -g @angular/cli
npm install -g @angular/cli@latest

Even if you update the global CLI, it won't affect the projects you created before with older versions. In that case, the version of a project will have priority so you might want to update the version of the project to match your global version. You can do that by going to the project file and run the following the commands below

rm -rf node_modules
npm uninstall @angular/cli --force
npm install @angular/cli@latest --force
npm i --force

You might have errors after running all the commands above in VS Code. If that is the case, open the global search and find the 'reload window', and run it. This cleans up the project and reflects changes.


How to check the version and version history (https://github.com/angular/angular-cli/releases)

Version Checking

Use either of the commands below to check the version

ng version
ng v

A Command for Additional Information for Each Command

For general information, use the command below

ng help

If you want to know more about a certain command, append the help option after the command

ng new --help
When CLI is properly installed,  you can use Angular CLI commands with 'ng'
Commands (Most commands have options that can be specified with '--' before the full command (e.g., --open). You can also use an alias (shortcut) with '-' in front of a shortened command (e.g., -o)

Creating a Project

Use the command below to create an Angular project (workspace)

Creating one project,

ng new project-name

After creating a project, move to the project with the command below

cd project-name

Creating Multiple Projects under A Workspace,

Create a workspace

ng new my-workspace --no-create-application

Then move to the workspace

cd my-workspace

Create applications under the workspace

ng generate application my-first-app

Run

Now that we have seen how we can create a project, let's see how we can run the application. The default port is 'http://localhost:4200/'
 
The first command runs the application but does not automatically open the application window
ng serve

If you want to open the application window automatically, use this command

ng serve --open

You can also use the shortcut for this

ng serve -o

Angular Project Structure


 
 

References

 

Angular

 

angular.io

 

Releases · angular/angular-cli

CLI tool for Angular. Contribute to angular/angular-cli development by creating an account on GitHub.

github.com

 

Angular

 

angular.io

How to upgrade Angular CLI to the latest version - Stack Overflow

 

How to upgrade Angular CLI to the latest version

Using ng --version I got: @angular/cli: 1.0.0 which is not the latest release available. Since I have Angular CLI globally installed on my system, in order to upgrade it I tried: npm update a...

stackoverflow.com

 

728x90
반응형

'Frontend > Angular' 카테고리의 다른 글

Angular(Compiler) - JIT VS AOT  (1) 2023.03.21
Angular - Project Structure  (0) 2023.03.21
Lazy Loading  (0) 2023.03.20
Angular - How to Use HTTPS in Development  (1) 2023.03.12
Angular Forms - Reactive Form  (0) 2023.03.10