Skip to content

bwy111/babel-plugin-replace

Repository files navigation

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()

About

babel插件-替换全局变量

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published