$ cnpm install babel-plugin-global-define
The GlobalDefine plugin allows you to create global constants which is similar to Webpack's DefinePlugin
npm i babel-plugin-global-define --save-dev
{
"plugins": [
["global-define", {
"__ENV__": "production",
}]
]
}
require("babel-core").transform("foo();", {
plugins: [
["global-define", { "__ENV__": "production" }]
]}
})
const hosts = {
development: 'https://test.github.com/',
production: 'https://www.github.com/'
}
const currentHost = hosts[__ENV__]
const hosts = {
development: 'https://test.github.com/',
production: 'https://www.github.com/'
}
const currentHost = hosts["production"]
Copyright 2013 - present © cnpmjs.org | Home |