Export an imported module

前端 未结 2 1152
一个人的身影
一个人的身影 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: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.

提交回复
热议问题