babel-plugin-transform-string-literal-replace
v1.0.2
Published
Babel plugin to find and replace strings in source code
Downloads
181
Readme
string-literal-replace
A simple Babel plugin to transform source code by finding and replacing string literals with other values.
Use Case
Inject constants and other snippets into source code.
Usage
.babelrc
{
"plugins": [
["transform-string-literal-replace", {
"Sebastiaan": "Seb",
"SOME_MESSAGE": 1234567890
}]
]
}
import {transform} from 'babel-core'
const input = `var name = 'Sebastiaan';alert('SOME_MESSAGE');`
const output = transform(input)
// -> `var name = 'Seb';alert(1234567890);`
Options
pattern
An Object
or Map
containing strings to replace with values that are either String
, Number
, Boolean
, or null
.