Is it possible to import modules from all files in a directory, using a wildcard?

前端 未结 13 2201
陌清茗
陌清茗 2020-11-22 04:25

With ES6, I can import several exports from a file like this:

import {ThingA, ThingB, ThingC} from \'lib/things\';

However, I like the orga

13条回答
  •  没有蜡笔的小新
    2020-11-22 04:54

    I don't think this is possible, but afaik the resolution of module names is up to module loaders so there might a loader implementation that does support this.

    Until then, you could use an intermediate "module file" at lib/things/index.js that just contains

    export * from 'ThingA';
    export * from 'ThingB';
    export * from 'ThingC';
    

    and it would allow you to do

    import {ThingA, ThingB, ThingC} from 'lib/things';
    

提交回复
热议问题