You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP

babel-plugin-transform-imports

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-imports

Transforms member style imports (import {x} from 'y') into default style imports (import x from 'y/lib/x')

2.0.0
latest
Version published
Weekly downloads
209K
5.39%
Maintainers
1
Weekly downloads
 
Created

What is babel-plugin-transform-imports?

babel-plugin-transform-imports is a Babel plugin that allows you to transform import statements in your JavaScript code. This can be useful for optimizing bundle sizes by enabling tree-shaking, aliasing imports, or converting import paths.

What are babel-plugin-transform-imports's main functionalities?

Tree-shaking

This feature allows you to import only the parts of a library that you need, which can significantly reduce the size of your JavaScript bundle. In this example, importing from 'lodash' will be transformed to import only the specific lodash function, preventing full library imports.

{
  "plugins": [
    [
      "transform-imports",
      {
        "lodash": {
          "transform": "lodash/${member}",
          "preventFullImport": true
        }
      }
    ]
  ]
}

Aliasing Imports

This feature allows you to alias import paths, making it easier to manage and refactor your code. In this example, importing from 'my-library' will be transformed to import from 'my-library/dist/${member}', allowing for more flexible and maintainable import paths.

{
  "plugins": [
    [
      "transform-imports",
      {
        "my-library": {
          "transform": "my-library/dist/${member}",
          "preventFullImport": true
        }
      }
    ]
  ]
}

Custom Import Paths

This feature allows you to define custom import paths for your modules. In this example, importing from 'components' will be transformed to import from './src/components/${member}', making it easier to manage and organize your project structure.

{
  "plugins": [
    [
      "transform-imports",
      {
        "components": {
          "transform": "./src/components/${member}",
          "preventFullImport": true
        }
      }
    ]
  ]
}

Other packages similar to babel-plugin-transform-imports

FAQs

Package last updated on 01 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