Socket
Socket
Sign inDemoInstall

babel-plugin-import-expander

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-import-expander

Expand multiple members `import` to specific module `import`


Version published
Maintainers
1
Install size
97.5 kB
Created

Readme

Source

babel-plugin-import-expander

Build Status npm version

Expand multiple members import to specific module import, mainly for performance concerns.

Example

In
import { A, B, C as D } from '../components';
Out
import A from '../components/A/A';
import B from '../components/B/B';
import D from '../components/C/C';

Installation

$ npm install babel-plugin-import-expander --save-dev

Usage

{
  "plugins": [
    ["import-expander", {
      "rules": {
        "condition": "^(\\.|\\/).*\\/components$",
        "template": "{source}/{name}/{name}"
      }
    }]
  ]
}
  • rules

    Options can be one object or a list of objects, each object has two properties:

    • condition

      One or multiple string format regular expressions, if the source of ImportDeclaration matches any of them, it will be replaced by the following template.

    • template

      Used to replace hit source with a simple variable placeholder presentation. There are mainly two variable placeholders: {source} represents the source of ImportDeclaration, and {name} represents imported name.

Via Node API
require('babel-core').transform('code', {
  plugins: ['import-expander', {
    rules: {
      condition: '^(\\.|\\/).*\\/components$',
      template: '{source}/{name}/{name}'
    }
  }],
});

Keywords

FAQs

Last updated on 22 Feb 2019

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc