Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

342
Visualizações
enable production mode in angular 2

I have been creating 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'm tried ng build -prod; ng serve ,but still not working.

Thanks in advance.

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

ng build --prod will create build artifacts in the /dist folder - you have to put those files on a different web server (i.e. you don't use ng serve after that).

If you just want to run your app using ng serve but using production mode, then use:

ng serve --prod

Edit

I don't seem to be doing a good job of explaining this. Your request is to "enable production mode". You have two ways of doing that, depending on what you're trying to do.

If you want to use the angular-cli development server to run your app in production mode as a means of testing to see if production mode works properly, then use:

ng serve --prod

If, however, you are ready to deploy your app to a production web server, then it's a two step process:

  1. generate the production-ready version of your app using: ng build --prod

  2. copy the output of the /dist folder onto your production web server

Note that I don't do both - i use either ng build or ng serve , depending on what I'm trying to accomplish.

about 4 years ago · Santiago Trujillo Relatório

0

ng serve --prod didn't worked for me.

This worked btw 😊

ng serve --configuration=production

it creates a test production server which works same as it works on the deployed one. I tried this testing with environment.js (all other solutions didn't worked for me)

You can follow this (Becoming an Angular Environmentalist) article to learn more about Angular environments

about 4 years ago · Santiago Trujillo Relatório

0

You should try again with ng run build --prod or npm run build as for me, in my package.json file, I setting script like that

"scripts":{
 "ng": "ng",
 "publish": "ng build --prod",
 "start": "ng serve --host 0.0.0.0 --port 4200",
 "hmr": "ng serve --host 0.0.0.0 --port 4200 4201 --hmr -e=hmr",
 "test": "ng test",
 "pree2e": "webdriver-manager update --standalone false --gecko false",
 "e2e": "protractor"},..

and then so, when I want to build(publish) my angular project, I used npm run publish command. If you want to change "build" instead of "publish", you must use like "npm run build" It will OK.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda