angular / angular/angular

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

Open
#51,175 21 comments 76 reactions 0 assignees View on GitHub
area: core feature feature: under consideration
Dominant language
TypeScript
Stars
101k
Forks
27.5k
Avg merge
1d 19h
Merged PRs (30d)
288

Description

### 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:

```ts
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.

Contributor guide

Open the contributing guide

Research direction

Start in Angular's core package by tracing the existing ngDevMode/isNgDevMode implementation and how public API exports are defined. Review the development-only checks described in the issue and the production-bundle behavior. Done means the variable is publicly available to Angular libraries and user code, with relevant tests confirming the intended production build behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
api, frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.