Enable production mode in angular 2
I am creating a web application using Angular 2 and Firebase, I want to enable production mode.
main.ts
if (environment.production) {
enableProdMode();
}
environment.ts
export const environment = {
production: true
};
environment.prod.ts
export const environment = {
production: true
};
Then I tried ng build -prod; ng, but still doesn't work.
Thanks in advance.
source to share
ng build --prod
will create build artifacts in the folder /dist
- you have to put these files on another web server (i.e. don't use ng service after that).
If you just want to start your application with ng serve
, but using production mode, then use:
ng serve --prod
Edit
I don't seem to explain it very well. Your request should "enable production mode". You have two ways to do this, depending on what you are trying to do.
If you want to use the angular-cli dev server to run your application in production as a testing tool, to ensure that the run mode is working correctly, use:
ng serve --prod
If, however, you are ready to deploy your application to a production web server, then this is a two step process:
-
create a finished version of your application using:
ng build --prod
-
copy the output of the folder
/dist
to your production web server
Note that I am not doing both: I use either ng build
or ng serve
, depending on what I am trying to accomplish.
source to share
I've observed this in angular-cli 1.0.0-beta.28.3
. dist
disappears on ng-serve
. If you want to keep the assembly try ng build --output-path=last-build/
and see this issue .
But the point is, you don't have to do it ng serve --prod
after creation build
. As @snorkpete says, copy the folder dist
after building the assembly to your webserver. And your web server will take care of running the application. Remeber, you will have to create a virtual host for this
... But if you just want to run it on your local machine and want to live webpack
, just do ng serve --prod
, live webpack
has nothing to do with dist
which you have.
source to share