0.1.0 • Published 3 years ago

babel-plugin-replace v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

babel-plugin-replace

介绍

替换js全局变量的babel插件

安装

yarn add babel-plugin-replace --dev
npm install babel-plugin-replace -D

使用

.babelrc

With options:

{
  "plugins": [
    ["babel-plugin-replace", {{
      "objNameMap": {
        "wx": "tt",
      },
      "variableStartsWith": "$$Variable",
      "variable": {
        "Debug": true,
        "Version": "1.2.3",
      },
    }]
  ]
}

转换前

const debug = '$$VariableDebug'
const version = '$$VariableVersion'

wx.getUser()
wx.getLocation()
applicationCache.wx.set()

转换后

const debug = true
const version = "1.2.3"

tt.getUser()
tt.getLocation()
applicationCache.wx.set()