Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving and testing a bundle after ng build

Tags:

angular-cli

After I build a bundle with ng build --prod --aot I would like to quickly serve it locally. Is there a way to quickly serve the /dist directory locally using @angular/cli?

I tried to cd dist && ng serve but the dist disappears when the ng serve command is run.

like image 884
user776686 Avatar asked Apr 27 '17 11:04

user776686


People also ask

What happens after ng build?

After coding our Angular apps using TypeScript, we use the Angular CLI command to build the app. ng build command compiles the application into an output directory and the build artifacts will be stored in the dist/ directory.

How check ng serve?

Quick update : You can run ng test as you run ng serve by configurating your test launcher (usually karma). For example with karma, you can set the property singleRun to false so that it will re-launch the test when you change some files.

Does ng serve also build?

ng servelink. Builds and serves your application, rebuilding on file changes.


1 Answers

http-server is what I use, and it works well.

Install:

npm install -g http-server

cd into your dist folder, type http-server, then enter. Or, just do http-server .\dist at the command line after your application build is successful.

Open a browser, and go to http://127.0.0.1:8080

More info: https://www.npmjs.com/package/http-server

I use this on all my dev machines for running built ng applications.

Or, was there more than simply seeing if the application runs (smoke test) that you were looking for in this?

like image 76
R. Richards Avatar answered Oct 09 '22 06:10

R. Richards