The `detect-bundler` package provides build-time flags to identify if the current code is being bundled for a web browser (e.g., via Webpack, Browserify) or for React Native (via Metro). Unlike runtime environment detection, this library leverages the `package.json` `browser` field specification to resolve platform-specific code paths during the build process, ensuring zero runtime overhead. Its current stable version is 1.1.0. Given its focused utility, new releases are infrequent and primarily address minor updates or compatibility fixes rather than new features. This design choice makes it particularly useful for libraries or applications needing to conditionally include platform-specific logic without impacting runtime performance, differentiating it from solutions that rely on `navigator` or `process` checks.
npm install detect-bundlerVerified import paths — ran on the pinned version, not inferred.
Demonstrates importing and using the `isBrowser` and `isReactNative` flags to conditionally execute platform-specific code at build time.
Understand that these flags become static boolean constants in your bundled output. Use them for conditional imports or code paths that are resolved *before* your application runs, not for runtime environment switching. For runtime detection, use standard browser APIs (e.g., `window` object) or Node.js `process` globals.
Ensure that code paths guarded by `isBrowser` or `isReactNative` are truly only executed or imported when the respective flag is statically true for the current build target. This may involve proper bundler configuration for conditional exports or environment targets.
Verify your bundler configuration (e.g., Webpack `target`, Metro configuration) and how it interprets the `package.json` `browser` field. If `isBrowser` is unexpectedly `false`, your bundler might be resolving to the Node.js version of the package, even if the eventual target is a browser.
No dependency data recorded yet.