Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when you run ng serve?

I've been using Angular-CLI for the last little while. It comes with a number of commands including ng serve which spins up a server at localhost:4200.

I'm used to using Grunt and Gulp which can be configured to suit my needs. I wanted to configure Angular-CLI's server but then I realized I didn't know what it was or how to configure it. Grepping the project for serve hasn't unearthed anything that seems useful.

So, what exactly does ng serve do?

like image 763
Jason Swett Avatar asked May 10 '16 11:05

Jason Swett


People also ask

What does ng serve command do?

When you use the ng serve command to build an application and serve it locally, the server automatically rebuilds the application and reloads the page when you change any of the source files. When you run ng new my-first-project a new folder, named my-first-project , will be created in the current working directory.

What happens on NG serve angular?

ng serve command builds and serve the application. It rebuilds the application if changes occur. Here project is the name of the application as defined in angular. json.

Does ng serve also build?

The ng serve command does not write build and it builds artifacts from memory instead for a faster development experience. This command builds your app and deploys it.


1 Answers

Nowadays, it uses webpack-dev-server to start a local webserver. See this question.

From the docs:

The CLI supports running a live browser reload experience to users by running ng serve. This will compile the application upon file saves and reload the browser with the newly compiled application. This is done by hosting the application in memory and serving it via webpack-dev-server.


Original answer:

After some research here's what I've gathered.

Angular-CLI piggybacks certain things off of Ember CLI. It would appear that ng serve is one of those things. Ember has an ember server command which is defined in this file and seems to match the behavior of ng serve.

like image 143
Jason Swett Avatar answered Oct 17 '22 17:10

Jason Swett