Where does `ng serve` output files to?

34,153

Solution 1

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

Solution 2

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?

Share:
34,153

Related videos on Youtube

Daniel Patrick
Author by

Daniel Patrick

I like to build sandcastles

Updated on April 11, 2020

Comments

  • Daniel Patrick
    Daniel Patrick about 4 years

    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.

    • Jsandesu
      Jsandesu over 5 years
    • Daniel Patrick
      Daniel Patrick over 5 years
      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
    Daniel Patrick over 7 years
    Thanks Steven! I missed that question.
  • user1275105
    user1275105 almost 7 years
    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.
  • Meligy
    Meligy almost 7 years
    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.
  • iMe
    iMe almost 7 years
    Is there any way I can get the browser to auto-refresh every time the build is done, like ng serve does?
  • Meligy
    Meligy almost 7 years
    Nothing built into the CLI itself does that, because no server to call the browser to trigger the refresh.
  • Pardeep Jain
    Pardeep Jain over 4 years
    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?
  • Meligy
    Meligy over 4 years
    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.
  • tinkering.online
    tinkering.online about 4 years
    @iMe I found something on the official angular pages that might be of interest for your live build + serve question: angular.io/guide/deployment#building-and-serving-from-disk