babel-plugin-transform-replace-expressions weekly downloads statistics
By jviide · npm · Babel plugins
Replace JavaScript expressions with other expressions
babel-plugin-transform-replace-expressions has 134,418 recorded weekly downloads on npm, a decrease of 12.1% over the past 30 days, ranking #595 of 3,247 tracked listings.
About babel-plugin-transform-replace-expressions
babel-plugin-transform-replace-expressions

Replace JavaScript expressions with other expressions.
Installation
$ yarn add --dev babel-plugin-transform-replace-expressions
Example
Input file:
const env = process.env.NODE_ENV;
typeof Hello === "number";
.babelrc:
{
"plugins": [
[
"babel-plugin-transform-replace-expressions",
{
"replace": {
"process.env.NODE_ENV": "\"production\"",
"typeof Hello": "42"
}
}
]
]
}
Output:
const env = "production";
42 === "number";
Conflict resolution
A conflict happens when two replacements have the same Babel abstract syntax tree representation. For example expressions typeof A and typeof (A) are formatted differently but have the same AST representation as far as the plugin is concerned. In those situations the default is to raise an error, and can be overwritten by setting the option allowConflictingReplacements to true.
You can also always give the replacements as an array of key-value pairs. When allowConflictingReplacements is set to true the last conflicting replacement gets selected.
{
"plugins": [
[
"babel-plugin-transform-replace-expressions",
{
"replace": [
["typeof A", "B"],
["typeof (A)", "C"]
],
"allowConflictingReplacements": true
}
]
]
}
Notes
-
Replacements are only applied to expressions. Therefore replacing
DEBUGwithfalseinconst DEBUG = truedoes nothing, but forif (DEBUG) {}the result isif (false) {}. -
Only full expressions count. You can't replace
envinprocess.env.NODE_ENV, you have to replaceprocess.env, which is a proper expression in Babel AST. -
A replacement is only applied when the result is valid JavaScript. For example replacing
awith2in the following code:a = 1; b = a;yields
a = 1; b = 2;
License
This plugin is licensed under the MIT license. See LICENSE.
Description from the npm listing.
- babel-plugin
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (170)Similar npm Babel plugins plugins
All 20 babel-plugin-transform-replace-expressions alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/babel-plugin-transform-replace-expressions. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.