Production safety
Hakka is a development tool. None of its capture, storage, or UI code should run — or even link — in a production build. Each platform has a different mechanism for guaranteeing this.
Gate start() behind the runtime dev flag for your environment. Hakka is a no-op until start() is called, so a skipped call is a skipped capture — no interceptors installed, no memory allocated.
React Native
import { Hakka } from 'hakka-react-native'
if (__DEV__) { Hakka.start({ mode: 'auto' })}__DEV__ is true in debug builds and false in release builds. Metro strips the unreachable branch from the production bundle.
Vite / web
import { start } from 'hakka-browser'
if (import.meta.env.DEV) { start()}import.meta.env.DEV is replaced at build time. The if body is tree-shaken out of production bundles.
The register() call lives in instrumentation.ts. Re-export it directly — register() self-guards: in production Next.js builds process.env.NODE_ENV is "production" and it returns before any interceptors are installed.
export { register } from 'hakka-node/next'register() is called once per runtime process startup. In production it short-circuits to zero initialization — no fetch patching, no node http/https hooks, no storage. (It also skips the Edge runtime automatically, so nothing here reaches an Edge bundle.)
Android uses Gradle’s debugImplementation / releaseImplementation split. The hakka-network-noop artifact provides the same public API as hakka-network but every method is a no-op. The real capture code is never compiled into the release APK or AAB.
dependencies { // Network capture — real impl in debug, no-op stub in release debugImplementation("com.noodleapps.hakka:hakka-network:0.1.0") releaseImplementation("com.noodleapps.hakka:hakka-network-noop:0.1.0")
// Optional performance collectors — same pattern debugImplementation("com.noodleapps.hakka:hakka-performance:0.1.0") releaseImplementation("com.noodleapps.hakka:hakka-performance-noop:0.1.0")}The no-op variants have no OkHttp dependency, no storage, and no UI. R8/ProGuard can inline the empty stubs away entirely.
Do not add hakka-ui to releaseImplementation — the inspector overlay has no no-op counterpart and should not ship in production.
iOS uses Swift Package Manager conditional product selection. Link HakkaNetworkNoop in release configurations and HakkaNetwork in debug. The no-op product compiles to a handful of empty stubs with no URLProtocol registration, no storage, and no URLSession swizzling.
// Debug — full capture// Add HakkaNetwork to your target's linked frameworks// Release — no-op stub// Link HakkaNetworkNoop instead of HakkaNetworkThe HakkaUI SwiftUI inspector overlay is a separate product. Gate the import and any HakkaUI.show() call behind a compile-time flag so it never links into release:
#if DEBUGimport HakkaUI
HakkaUI.show()#endifWhat each guard prevents
Section titled “What each guard prevents”| Guard | Capture runs? | Code linked in release? | Binary size impact |
|---|---|---|---|
__DEV__ / import.meta.env.DEV |
No | Yes (tree-shaken) | Negligible after bundling |
Next.js NODE_ENV guard |
No | Yes (dead branch) | Zero — register() returns immediately |
Android debugImplementation |
No | No — noop artifact only | Zero |
iOS HakkaNetworkNoop |
No | No — noop product only | Zero |