80

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?

Jason Swett
  • 43,526
  • 67
  • 220
  • 351

1 Answers1

49

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.

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
Jason Swett
  • 43,526
  • 67
  • 220
  • 351
  • 7
    One thing I cannot figure out is which folder is being served to the browser with ng-serve. I thought it would be running ng-build (ie, output to the outdir folder in the config) and serving that, however you can erase that folder while http://localhost:4200/ is running and it has no effect. So where is it compiling all of the bundles to? UPDATE: Here is the answer - in memory: http://stackoverflow.com/questions/40087369/where-does-ng-serve-output-files-to – Rodney Nov 06 '16 at 19:13
  • 9
    I wonder how much this answer still applies now that Angular CLI uses Webpack. – Jason Swett Dec 29 '16 at 15:42