Export an imported module

前端 未结 2 1117
一个人的身影
一个人的身影 2021-02-05 01:18

I have two javascript modules that looks like this:

// inner/mod.js
export function myFunc() {
   // ...
}

// mod.js
import * as inner from \"./inner/mod\";


        
相关标签:
2条回答
  • 2021-02-05 01:51

    I believe what you are looking for is

    export * from './inner/mod';
    

    That will reexports all exports of ./inner/mod. The spec actually has very nice tables listing all the possible import and export variants.

    0 讨论(0)
  • 2021-02-05 01:52
    // inner/mod.js
    export function myFunc() {
       // ...
    }
    
    // mod.js
    import { myFunc } from "./inner/mod";
    export { myFunc };
    

    Try to be explicit in what you import, the less the better, because of that I've changed your import in mod.js. If you do import *, you define a variable which will be the object of all names exports from that module you imported.

    re-exporting is the same as making something of your own and exporting.

    0 讨论(0)
提交回复
热议问题