New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-no-index-imports

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-no-index-imports

This plugin can transform index imports into direct file imports.

1.1.0
latest
Source
npm
Version published
Weekly downloads
44
109.52%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-no-index-imports

This plugin can transform index imports into direct file imports.

For example, the plugin can transform imports such as

import { Homepage } from '@components';

Into either default style or named imports targeting a specific file.

import { Homepage } from '@components/Homepage';

This can/will improve tree-shaking and reduce bundle size.

Installation

yarn add -D babel-plugin-no-index-imports

Usage

Add following config in your .babelrc

{
  "plugins": [
    ["babel-plugin-no-index-imports", {
      "extensions": ["js", "jsx", "ts", "tsx"],
      "useDefaultImport": false,
      "stripFileExtension": true,
      "extractName": function(filename) {
        return filename.substr(0, filename.lastIndexOf('.'));
      },
      "selectImport": function(importName, imports, member) {
        return imports[0];
      },
      "prefixes": {
        "@components": "./src/workspaces",
        "@utils": "./src/utils"
      }
    }]
  ]
}

Keywords

babel

FAQs

Package last updated on 12 Oct 2022

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