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