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

前端 未结 13 2208
陌清茗
陌清茗 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:43

    Just an other approach to @Bergi's answer

    // lib/things/index.js
    import ThingA from './ThingA';
    import ThingB from './ThingB';
    import ThingC from './ThingC';
    
    export default {
     ThingA,
     ThingB,
     ThingC
    }
    

    Uses

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

提交回复
热议问题