Skip to content

LiamMartens/babel-plugin-no-index-imports

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 

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"
      }
    }]
  ]
}

About

Babel plugin to transform index like imports into direct imports

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published