Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/liammartens/babel-plugin-no-index-imports
Babel plugin to transform index like imports into direct imports
https://github.com/liammartens/babel-plugin-no-index-imports
Last synced: 11 days ago
JSON representation
Babel plugin to transform index like imports into direct imports
- Host: GitHub
- URL: https://github.com/liammartens/babel-plugin-no-index-imports
- Owner: LiamMartens
- License: mit
- Created: 2021-04-06T16:00:51.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-12T14:03:55.000Z (about 2 years ago)
- Last Synced: 2024-11-19T17:01:36.929Z (about 1 month ago)
- Language: TypeScript
- Size: 22.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# babel-plugin-no-index-imports
This plugin can transform index imports into direct file imports.For example, the plugin can transform imports such as
```js
import { Homepage } from '@components';
```Into either default style or named imports targeting a specific file.
```js
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"
}
}]
]
}
```