__DEV__ Gating
Three layers of stripping:
- Runtime —
is_dev()readsglobalThis.__DEV__if set, else falls back toprocess.env.NODE_ENV !== "production". SetglobalThis.__DEV__ = falseearly in your bootstrap to globally disable debug output. debug({ dev: false })— short-circuit individual debug instances.debug_noop()— a zero-overhead stub. Pass into the harness/boot when you want compile-time tree-shaking of debug calls (production builds).
Bundler-define pattern (rolldown/rolldown-vite):
export default { // ... define: { __DEV__: process.env.NODE_ENV === "production" ? "false" : "true", },};When __DEV__ resolves to a literal false, dead-branch elimination drops the debug emit calls entirely.