babel-plugin-import-globals

2.0.0 • Public • Published

babel-plugin-import-globals

Automatically import a whitelist of modules when they are used. This is a bit like setting a global variable, except that it is isolated to your project (it does not affect dependencies or dependents of the module as they will not be running your babel transforms). This can save a lot of time with the few core modules that are used everywhere, while still leaving most modules using the standard import foo from 'foo' syntax so it's very explicit where something comes from.

Build Status Dependency Status NPM version

Installation

npm install babel-plugin-import-globals --save

Usage

Put something like this in your .babelrc:

.babelrc

{
  "plugins": [
    [
      "import-globals",
      {
        "React": "react",
        "Component": {"moduleName": "react", "exportName": "Component"},
        "PropTypes": {"moduleName": "react", "exportName": "PropTypes"}
      }
    ]
  ]
}

And then you can just do

class MyElement extends Component {
  static propTypes = {
    name: PropTypes.string.isRequired,
  };
  render() {
    return <div>{this.props.name}</div>
  }
}

And this tool will magically add in:

import React, {Componet, PropTypes} from 'react';
 
class MyElement extends Component {
  static propTypes = {
    name: PropTypes.string.isRequired,
  };
  render() {
    return <div>{this.props.name}</div>
  }
}

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-import-globals

Weekly Downloads

553

Version

2.0.0

License

MIT

Unpacked Size

6.63 kB

Total Files

5

Last publish

Collaborators

  • forbeslindesay