Skip to content

Provide the ability to remove code needed only in dev mode from the production bundle #51175

@markostanimirovic

Description

@markostanimirovic

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Several NgRx libraries have features/checks that are only used in development mode (e.g. store runtime checks, component store lifecycle hooks check, store devtools, etc).

Proposed solution

Expose the ngDevMode/isNgDevMode variable to the public API, so it can be used in Angular libraries that have dev mode-related functionalities, but also in user codebases if needed.

This feature could significantly reduce the size of production bundles in many Angular codebases.

Alternatives considered

Currently, we can use ngDevMode to remove dev mode-related logic from the production bundle in the following way:

declare const ngDevMode: boolean;
const isNgDevMode = typeof ngDevMode === 'undefined' || !!ngDevMode;

// ...

if (isNgDevMode) {
  console.warn('@ngrx/store: ...');
}

However, this global variable is not part of the public API and it can be risky to rely on it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimefeatureIssue that requests a new featurefeature: under considerationFeature request for which voting has completed and the request is now under consideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions