babel-plugin-transform-dev

raw JSON →
2.0.1 verified Sat Apr 25 auth: no javascript maintenance

Babel v6 plugin that replaces all occurrences of __DEV__ with the evaluation of "production" !== process.env.NODE_ENV. Currently at version 2.0.1, with no recent updates. It simplifies stripping development-only code from production bundles. Unlike similar plugins, it evaluates the expression at build time, replacing __DEV__ with a boolean literal. Limited to Babel v6; unmaintained since 2018. Use @babel/plugin-transform-dotenv or custom plugins for modern Babel.

error Plugin/transform-dev is not a valid plugin
cause Using with Babel v7+ which does not support this plugin.
fix
Switch to @babel/plugin-transform-dev or another alternative.
error ReferenceError: __DEV__ is not defined
cause Plugin did not transform __DEV__ because it wasn't applied.
fix
Verify plugin is included in .babelrc and Babel is running correctly.
error TypeError: Cannot read property 'evaluate' of undefined
cause Incorrect plugin configuration syntax in .babelrc.
fix
Use array syntax: ['transform-dev', { evaluate: false }].
breaking Package is designed for Babel v6 only; does not work with Babel v7+.
fix Use @babel/plugin-transform-dev or a custom plugin for Babel v7+.
deprecated Last release 2018; no active maintenance or security updates.
fix Consider alternatives like @babel/plugin-transform-dotenv or custom babel macros.
gotcha Assumes process.env.NODE_ENV is set; otherwise __DEV__ is always true.
fix Ensure your build system defines NODE_ENV (e.g., 'production' via webpack DefinePlugin).
npm install babel-plugin-transform-dev
yarn add babel-plugin-transform-dev
pnpm add babel-plugin-transform-dev

Demonstrates replacing __DEV__ with a boolean based on environment variable.

// install: npm install babel-plugin-transform-dev
// .babelrc
{
  "plugins": ["transform-dev"]
}

// input.js
const isDev = __DEV__;
if (__DEV__) {
  console.log('dev only');
}

// output (with NODE_ENV=production)
const isDev = false;
if (false) {
  console.log('dev only');
}