How to enable production mode?

后端 未结 14 1220
忘掉有多难
忘掉有多难 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:24

    When I built a new project using angular-cli. A file was included called environment.ts. Inside this file is a variable like so.

    export const environment = {
      production: true
    };
    

    Then in main.ts you have this.

    import './polyfills.ts';
    import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
    import { enableProdMode } from '@angular/core';
    import { environment } from './environments/environment';
    import { AppModule } from './app/';
    
    if (environment.production) {
      enableProdMode();
    }
    
    platformBrowserDynamic().bootstrapModule(AppModule);
    

    You could add this to a non angular-cli project, I would assume, because enableProdMode() is being imported from @angular/core.

提交回复
热议问题