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.
Common errors
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 }].
Warnings
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).
Install
npm install babel-plugin-transform-dev yarn add babel-plugin-transform-dev pnpm add babel-plugin-transform-dev Imports
- default wrong
const plugin = require('babel-plugin-transform-dev')correctimport plugin from 'babel-plugin-transform-dev' - N/A (Plugin Usage) wrong
module.exports = { plugins: ['babel-plugin-transform-dev'] }correctmodule.exports = { plugins: ['transform-dev'] } - N/A (Plugin Options) wrong
module.exports = { plugins: ['transform-dev'], options: { evaluate: false } }correctmodule.exports = { plugins: [['transform-dev', { evaluate: false }]] }
Quickstart
// 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');
}