How to enable production mode?

后端 未结 14 1151
忘掉有多难
忘掉有多难 2020-11-29 16:44

I was reading related questions and I found this one, but my question is how can I switch from development to production mode. There are some differences between the modes w

相关标签:
14条回答
  • 2020-11-29 17:36

    ng build --prod replaces environment.ts with environment.prod.ts

    ng build --prod

    0 讨论(0)
  • 2020-11-29 17:36

    My Angular 2 project doesn't have the "main.ts" file mentioned other answers, but it does have a "boot.ts" file, which seems to be about the same thing. (The difference is probably due to different versions of Angular.)

    Adding these two lines after the last import directive in "boot.ts" worked for me:

    import { enableProdMode } from "@angular/core";
    enableProdMode();
    
    0 讨论(0)
  • 2020-11-29 17:38

    When ng build command is used it overwrite environment.ts file

    By default when ng build command is used it set dev environment

    In order to use production environment, use following command ng build --env=prod

    This will enable production mode and automatically update environment.ts file

    0 讨论(0)
  • 2020-11-29 17:39

    you can use in your app.ts || main.ts file

    import {enableProdMode} from '@angular/core';
    enableProdMode();
    bootstrap(....);
    
    0 讨论(0)
  • 2020-11-29 17:42

    You enable it by importing and executing the function (before calling bootstrap):

    import {enableProdMode} from '@angular/core';
    
    enableProdMode();
    bootstrap(....);
    

    But this error is indicator that something is wrong with your bindings, so you shouldn't just dismiss it, but try to figure out why it's happening.

    0 讨论(0)
  • 2020-11-29 17:45

    The best way to enable the production mode for an Angular 2 application, is to use angular-cli and build the application with ng build --prod. This will build the application with production profile. Using angular-cli has the benefit of being able to use development mode using ng serve or ng build while developing without altering the code all the time.

    0 讨论(0)
提交回复
热议问题