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