90

ng serve is not building to the path that I have set in my angular-cli.json in apps[0].outDir.

ng build works correctly and builds to the path that I have specified.

Daniel Patrick
  • 3,980
  • 6
  • 29
  • 49
  • Possible duplicate of [Where are files stored when running ng serve?](https://stackoverflow.com/questions/39256780/where-are-files-stored-when-running-ng-serve) – James Lawruk Sep 20 '18 at 18:09
  • 2
    Perhaps is a duplicate... but it seems that when folks google this question the wording here somehow serves them better, this has 4x the views. What's the standard way of resolving that? – Daniel Patrick Sep 21 '18 at 18:51

2 Answers2

128

It's correct that ng serve builds in memory.

Angular CLI does not have support for running a server and writing to disk at the same time.

If you are using your own server, etc., you can use ng build --watch, which will watch files just like ng serve, but will write them to disk, and will not run a server.

Check this official documentation on how to serve files from disk:
https://github.com/angular/angular-cli/wiki/stories-disk-serve

Meligy
  • 35,654
  • 11
  • 85
  • 109
  • 1
    Thanks for above. Would ng build concatenate and minify files? I ideally during development, I wouldn't want it to. We build on "dev containers" and don't need to spin up a development server. – user1275105 May 10 '17 at 11:40
  • 6
    It works in dev mode by default, which doesn't do minification / concatenation etc. When you are ready to ship, you run `ng build -prod` to get the optimized build. It does not spin a server either way. At work I host the site in IIS and develop using `ng build --watch`. – Meligy May 11 '17 at 00:17
  • 1
    Is there any way I can get the browser to auto-refresh every time the build is done, like `ng serve` does? – iMe Jul 07 '17 at 06:54
  • Nothing built into the CLI itself does that, because no server to call the browser to trigger the refresh. – Meligy Jul 07 '17 at 07:38
  • Can I customize `ng serve` command? I mean I want to run some bash commands say `node abc.js` before every `ng serve` is it possible? – Pardeep Jain Aug 08 '19 at 11:54
  • There might be something you can do in the `architect/serve` part of the `angular.json` file, but usually when people want to do that they make it an npm script in `package.json` and add what they want before `ng serve` and call this script instead of calling `ng serve` directly. – Meligy Aug 13 '19 at 01:55
  • @iMe I found something on the official angular pages that might be of interest for your live build + serve question: https://angular.io/guide/deployment#building-and-serving-from-disk – tinkering.online Feb 28 '20 at 21:15
17

Output is not written to disk when using ng serve. Everything will be kept in memory. Source: Where are files stored when running ng serve?

Community
  • 1
  • 1
Steven Yates
  • 2,400
  • 3
  • 30
  • 58