8

I need to BUILD my app using ng build --prod on machine #1 and to SERVE my app using ng serve --prod on machine #2

Machine #2 should NOT have the source files and has not the processing/RAM capacity to bundle them anyway.

I can't find a way to serve the already bundled files.

Any idea ?

Max
  • 696
  • 2
  • 9
  • 24
  • Related question: [webpack - How to serve an Angular 2 dist folder index.html - Stack Overflow](https://stackoverflow.com/questions/43389539/how-to-serve-an-angular-2-dist-folder-index-html). – Sergey Vyacheslavovich Brunov Nov 17 '19 at 02:19

1 Answers1

4

You could simply install a node Web Server on machine #2

npm install http-server -g
cd dist
http-server

At https://www.npmjs.com/package/http-server you'll find more information

Philip
  • 23,316
  • 2
  • 31
  • 31
  • Yes I know a lot of other http servers out there, but my requirements are to use angular-cli the serve my files. Furthermore, the index.html generated by ng build --prod do not include .gz bundles versions, so I guess ng serve compress them on the fly, and the result is 5 times smaller files loaded – Max Nov 24 '16 at 16:31
  • 1
    The webserver does the gzip compression if the Client sends the right ```Accept-Enconding``` headers see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding. Why do you need to use ng? – Philip Nov 24 '16 at 16:35
  • Tried to build with ng build --prod and to serve with http-server just now. Huge difference in loaded file sizes... – Max Nov 24 '16 at 16:35
  • 1
    Ok... I found the option "-g" of http-server :-D – Max Nov 24 '16 at 16:42
  • 1
    Thanks a lot btw :-) – Max Nov 24 '16 at 16:44