Search code examples
javascriptangulartypescriptngrxngxs

Should the NGXS NgxsLoggerPluginModule be removed for production builds?


During development we usually use the imports:

import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin';
import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin';

Should these be removed for production builds or is there benefit to keeping these intact with the production build (Troubleshooting production issues ...?)


Solution

  • I will sum up my comments for you in this answer:

    You usually remove such Plugins in prod env. It only consumes memory and doesn't give your customer a benefit. You can keep them in QA and DEV, at least, this is how I do it.

    Here is how I can handle it in my builds:

    // Module
    // example with ngrx, but it works the same with ngxs
    @NgModule({
      declarations: [AppComponent],
      imports: [
        ...,
        environment.devToolsEnabled
          ? StoreDevtoolsModule.instrument({
              maxAge: 50
            })
          : []
      ],
      providers: [...],
      bootstrap: [AppComponent]
    })
    export class AppModule {
      constructor() {}
    }
    
    // environment
    export const environment = {
      production: false,
      devToolsEnabled: true,
      ...
    };
    

    The environment.ts file will be overwritten by your specific environment file at build time with this flag:

    ng build --configuration=<<environment>>