22

What server does this Angular CLI command use, when using Angular CLI 1.6.0?

ng serve

Since webpack is now being used by the Angular CLI for the website bundling, does that mean ng-serve is using the webpack-dev-server (which is a Node.js Express server)? There is some indication in the following Q/A that ng serve possibly used to piggyback off a server used by Ember:

What happens when you run ng serve?

Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206
  • 2
    yes, angular cli uses webpack-dev-server. Here is a [doc](https://github.com/angular/angular-cli/blob/afbddfe348e532c48d272cf9b4273b9ef7af06c7/docs/documentation/stories/disk-serve.md) stating so – LLai Dec 07 '17 at 01:45

2 Answers2

12

Try ng eject This command will override your package.json and also generates a file called webpack.config.js in your root directory.

That will give you all the current webpack configuration that your project is using.

When you do that, in your package.json, this is what you'll find :

"scripts": {
    "eject": "ddc eject",
    "build": "webpack",
    "start": "webpack-dev-server",
    "test": "karma start ./karma.conf.js",
    "pree2e": "webdriver-manager update --standalone false --gecko false --quiet",
    "e2e": "protractor ./protractor.conf.js"
  },

As you can see, npm start is using webpack-dev-server.

NOTE: To undo your changes, use git, otherwise AngularCli doesn't provide a way of undoing

Milad
  • 27,506
  • 11
  • 76
  • 85
  • 1
    Thanks Milad. What's the link between ng serve and npm start? I've seen how npm start can call ng serve by using 'ng serve' as the value in scripts > start, but I haven't seen this the other way round (ng serve calling npm start). How does this work? – Chris Halcrow Dec 07 '17 at 05:22
  • `ng` is an AngularCli command and `npm whatever` is npm command, you can put your `ng commands` inside a `npm command` and call it that way, it's mostly useful when you haven't got AngularCli installed globally so you can't run `ng commands` in your command line, but you can run them with npm commands because npm will use angular-cli that is installed in your node_module ( not the global one) – Milad Dec 07 '17 at 10:50
  • Thanks Milad what I mean though is I don't understand how calling ng serve calls npm start, which then runs the webpack-dev-server – Chris Halcrow Dec 08 '17 at 05:20
  • The "eject" command has been temporaily disabled, as it is not yet compatible with the new angular.json format. The new configuration format provides further flexibilty to modify the configuration of your workspace without ejecting." Any ideas how to do it now? – MAESTRO_DE Jul 31 '18 at 06:08
  • 2
    The 'eject' command has been disabled and will be removed completely in 8.0. The new configuration format provides increased flexibility to modify the configuration of your workspace without ejecting. There are several projects that can be used in conjuction with the new configuration format that provide the benefits of ejecting without the maintenance overhead. One such project is ngx-build-plus found here: https://github.com/manfredsteyer/ngx-build-plus – averasko Feb 28 '19 at 19:35
2

Yup, its using webpack-dev-server. You can look at the source-code of the ng eject command:

https://github.com/angular/angular-cli/blob/6449a753641340d8fc19a752e1a1ced75f974efa/docs/documentation/1-x/eject.md

Govinda Sakhare
  • 5,009
  • 6
  • 33
  • 74
Sonu Kapoor
  • 1,567
  • 3
  • 16
  • 34
  • Above link is not working right now at least,But I got a following link which gives a documentation in markdown language. https://github.com/angular/angular-cli/blob/6449a753641340d8fc19a752e1a1ced75f974efa/docs/documentation/1-x/eject.md . It might help.And I think the above link did not work because ng eject is temporarily disabled from v6.0.0. – Deep Jul 04 '19 at 14:57