ES6 Modules: transitively exporting symbols (i.e., from imported files)

前端 未结 1 1392
無奈伤痛
無奈伤痛 2020-12-11 10:28

Suppose I\'m creating an ES6 library with multiple files, but have a root file that contains all of the top-level definitions. How could I achieve something like this exampl

相关标签:
1条回答
  • 2020-12-11 11:19

    You have to re-export:

    lib/main.js
    import { Sub } from './foo/sub';
    export { Sub };
    

    You can re-export directly like this:

    export { Sub } from './foo/sub';
    

    You can rename when exporting:

    export { Sub as MySub } from './foo/sub';
    

    Or re-export everything:

    export * from './foo/sub';
    
    0 讨论(0)
提交回复
热议问题