1.0.2 • Published 7 years ago

babel-plugin-transform-string-literal-replace v1.0.2

Weekly downloads
32
License
ISC
Repository
-
Last release
7 years ago

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.