babel-plugin-transform-resolve-wildcard-import
Transforms wildcard imports (import * as x from 'y';x.a();) to member style imports (import {a} from 'y';a();)
Last updated 2 years ago by gpittarelli .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install babel-plugin-transform-resolve-wildcard-import 
SYNC missed versions from official npm registry.

babel-plugin-transform-resolve-wildcard-import

Transforms wildcard style imports:

    import * as x from 'y';
    import * as w from 'z';
    x.a();
    x.b();
    console.log(Object.values(w));

into member style imports:

    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:)

    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)?)?)?$"
        ]}]
    ]
}

Current Tags

  • 0.1.1                                ...           latest (2 years ago)

4 Versions

  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.1                                ...           3 years ago
  • 0.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |