Export Imported Module

I have two javascript modules that look like this:

// inner/mod.js export function myFunc() { // ... } // mod.js import * as inner from "./inner/mod"; 

I would like to export myFunc from mod.js How can i do this?

EDIT: I must clarify that the function is exported, as expected, from inner/mod.js , but I also want to export funtion from external mod.js

For those seeking clarification, I would like to achieve this:

 // SomeOtherFile.js import * as mod from "mod"; // NOT inner/mod mod.myFunc(); 
+20
javascript ecmascript-6 es2015
Dec 23 '15 at 22:49
source share
2 answers

I believe what you are looking for

 export * from './inner/mod'; 

This will re-export all exports ./inner/mod . There are very good tables in the specification that list all possible options for import and export .

+40
Dec 23 '15 at 23:16
source share
 // inner/mod.js export function myFunc() { // ... } // mod.js import { myFunc } from "./inner/mod"; export { myFunc }; 

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

Re-exporting is the same as doing something of your own and exporting it.

+13
Dec 23 '15 at 22:59
source share



All Articles