Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gpittarelli/babel-plugin-transform-resolve-wildcard-import
Simple transform to strip some wildcard imports
https://github.com/gpittarelli/babel-plugin-transform-resolve-wildcard-import
babel babel-plugin es6 import
Last synced: about 2 months ago
JSON representation
Simple transform to strip some wildcard imports
- Host: GitHub
- URL: https://github.com/gpittarelli/babel-plugin-transform-resolve-wildcard-import
- Owner: gpittarelli
- License: mit
- Created: 2017-06-22T00:10:05.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-22T22:37:50.000Z (over 5 years ago)
- Last Synced: 2024-04-29T07:20:09.900Z (9 months ago)
- Topics: babel, babel-plugin, es6, import
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# babel-plugin-transform-resolve-wildcard-import
Transforms wildcard style imports:
```javascript
import * as x from 'y';
import * as w from 'z';
x.a();
x.b();
console.log(Object.values(w));
```into member style imports:
```javascript
import {a, b} from 'y';
import * as w from 'z';
a();
b();
console.log(Object.values(w));
```(well, that would be ideal, but actually it looks more like the
following, which is a bit simpler to implement:)```javascript
import {a as _a, b as _b} from 'y';
import * as w from 'z';
var x = {a: _a, b: _b};
x.a();
x.b();
console.log(Object.values(w));
```This is useful in some situations to get webpack and similar tools to
tree-shake better.Note: This plugin only works when the wildcard import (`x` in the
example) is only ever used in a property access. If you use `x`
directly, then we leave the wildcard import in place.## Options
By default this will apply to all wildcard imports, for example with a
.babelrc like:{
"plugins": ["babel-plugin-transform-resolve-wildcard-import"]
}If you only want it to apply this to certain import paths you can
restrict the transforms with an array of regular expressions passed as
`only`:{
"plugins": [
["babel-plugin-transform-resolve-wildcard-import", {only: [
"^lodash$",
"^\.\.?\/UI(\/(index(\.js)?)?)?$"
]}]
]
}