Registry / babel-plugin-inline-replace-variables

babel-plugin-inline-replace-variables

JSON →
library1.3.1jsnpmunverified

A Babel plugin that replaces identifier references with literal values during compilation. Version 1.3.1 is the latest stable release. It supports simple literal replacements (strings, booleans) as well as complex expressions via AST nodes. The plugin is commonly used for compile-time constants like __DEV__ or __VERSION__. Compared to alternatives like babel-plugin-replace-identifiers, this one replaces identifiers with literal values, not other identifiers. Low maintenance and simple API, suitable for projects using Babel 6/7.

npm install babel-plugin-inline-replace-variables
INSTALL
IMPORT
SIG · BABEL-PLUGIN-INLIN
B
babel-plugin-inline-replace-variables
javascriptv1.3.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (plugin)
import plugin from 'babel-plugin-inline-replace-variables'
const plugin = require('babel-plugin-inline-replace-variables')
CommonJS require also works, but ESM pattern shown. Plugin is used in Babel config.
plugin in .babelrc
['inline-replace-variables', { '__SERVER__': true }]
['babel-plugin-inline-replace-variables', { '__SERVER__': true }]
Use short name 'inline-replace-variables' in plugins array, not full package name.
t (babel-types)
import * as t from '@babel/types'
const t = require('babel-types')
Using AST node constructor from babel-types is deprecated; use @babel/types in Babel 7.

Replace __SERVER__ with true and __VERSION__ with a string literal using Babel plugin configuration.

// .babelrc or babel.config.js { "plugins": [ ["inline-replace-variables", { "__SERVER__": true, "__VERSION__": "1.0.0" }] ] } // input.js if (__SERVER__) { console.log('Server version:', __VERSION__); } // output.js if (true) { console.log('Server version:', "1.0.0"); }
Debug
Known issues
deprecatedPackage name changed: 'babel-plugin-inline-replace-varibles' (misspelled) is deprecated; use 'babel-plugin-inline-replace-variables'.
fix
npm uninstall babel-plugin-inline-replace-varibles && npm install babel-plugin-inline-replace-variables
affects: <1.0.1
gotchaPlugin only replaces identifiers with literal values, not other identifiers. If you need identifier-to-identifier replacement, use babel-plugin-replace-identifiers instead.
fix
Use babel-plugin-replace-identifiers for identifier replacement.
affects: >=1.0.0
gotchaWhen using AST node replacement via 'replacement' property, the node must be a valid Babel AST node; passing a string will be interpreted as a literal value, not a node.
fix
Use { type: 'node', replacement: /* AST node */ } for expression replacements.
affects: >=1.0.0
breakingBabel 6 vs Babel 7 compatibility: plugin may not work with Babel 7 without adjustment due to peer dependency on @babel/core.
fix
Ensure @babel/core is installed as a dev dependency and that the plugin is compatible (tested with Babel 7+).
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'babel-plugin-inline-replace-varibles'
Misspelled package name: 'varibles' instead of 'variables'.
fix
Install the correct package: npm install babel-plugin-inline-replace-variables --save-dev
ReferenceError: __SERVER__ is not defined
Variable used in source code but not replaced because plugin not configured or not running.
fix
Add the plugin to .babelrc with the replacement value for __SERVER__.
Error: Plugin configuration: [object Object] is not a valid replacement
Trying to use an object replacement without proper 'type' property.
fix
Use format: { '__KEY__': { type: 'node', replacement: someASTNode } }
Upgrade
Version history
1.3.1latest on npm
Audit
Dependencies
@babel/corerequiredpeer dependency for Babel plugin system
Agent activity
4 hits · last 30 days
node
4
Resources
babel-plugin-inline-replace-variables — npm install babel-plugin-inline-replace-variables · libregistry