babel-plugin-global-define

1.0.3 • Public • Published

babel-plugin-global-define

The GlobalDefine plugin allows you to create global constants which is similar to Webpack's DefinePlugin

Usage

install

npm i babel-plugin-global-define --save-dev

.babelrc

{
  "plugins": [
    ["global-define", {
      "__ENV__": "production",
    }]
  ]
}

Node API

require("babel-core").transform("foo();", {
    plugins: [
        ["global-define", { "__ENV__": "production" }]
    ]}
})

Example

In

const hosts = {
    development: 'https://test.github.com/',
    production: 'https://www.github.com/'
}
const currentHost = hosts[__ENV__]

Out

const hosts = {
    development: 'https://test.github.com/',
    production: 'https://www.github.com/'
}
const currentHost = hosts["production"]

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.3
    6,884
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.3
    6,884
  • 1.0.2
    0
  • 1.0.1
    0
  • 1.0.0
    1

Package Sidebar

Install

npm i babel-plugin-global-define

Weekly Downloads

6,885

Version

1.0.3

License

MIT

Last publish

Collaborators

  • zheng_refn