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

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

    if you don't export default in A, B, C but just export {} then it's possible to do so

    // things/A.js
    export function A() {}
    
    // things/B.js
    export function B() {}
    
    // things/C.js
    export function C() {}
    
    // foo.js
    import * as Foo from ./thing
    Foo.A()
    Foo.B()
    Foo.C()
    

提交回复
热议问题