-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: allow tree-shaking of dev-only code #2259
Conversation
In this commit, we're removing all const `NG_DEV_MODE` declarations and inlining `typeof ngDevMode !== 'undefined' && ngDevMode` conditions. This change is **required** for ESBuild tree-shaking to work properly. It has been observed that development-only code is not being dropped in production builds. For example, this code: ```js const NG_DEV_MODE = typeof ngDevMode !== 'undefined' && ngDevMode; if (NG_DEV_MODE) { ensureStateNameIsValid(stateName); } ``` Becomes the following after the build: ```js var NG_DEV_MODE$4 = !1; NG_DEV_MODE$4 && ensureStateNameIsValid(stateName); ``` Terser was able to inline `NG_DEV_MODE` variables, because it was able to evaluate their expressions during the build (that it's _falsy_) and remove them entirely.
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 0dd8a74. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
BundleMonFiles updated (3)
Unchanged files (3)
Total files change -145B -0.11% Groups updated (2)
Final result: ✅ View report in BundleMon website ➡️ |
BundleMon (NGXS Plugins)Files updated (4)
Unchanged files (5)
Total files change -77B -0.37% Groups updated (1)
Final result: ✅ View report in BundleMon website ➡️ |
Code Climate has analyzed commit 0dd8a74 and detected 3 issues on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 92.8% (50% is the threshold). This pull request will bring the total coverage in the repository to 95.3% (0.0% change). View more on Code Climate. |
BundleMon (Integration Projects)Files updated (3)
Total files change -1.6KB -0.77% Final result: ✅ View report in BundleMon website ➡️ |
In this commit, we're removing all const
NG_DEV_MODE
declarations and inliningtypeof ngDevMode !== 'undefined' && ngDevMode
conditions.This change is required for ESBuild tree-shaking to work properly. It has been observed that development-only code is not being dropped in production builds.
For example, this code:
Becomes the following after the build:
Terser was able to inline
NG_DEV_MODE
variables, because it was able to evaluate their expressions during the build (that it's falsy) and remove them entirely.