Socket
Book a DemoInstallSign in
Socket

babel-plugin-import-globals

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-import-globals

Automatically import a whitelist of modules when they are used

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 27 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts