I have two javascript modules that looks 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 should clarify that the function is being exported as expected from inner/mod.js
but I also want to export the funtion from the outer mod.js
.
To those asking for clarification, I would like to achieve this:
// SomeOtherFile.js import * as mod from "mod"; // NOT inner/mod mod.myFunc();
Modules can also contain a default export, using the default keyword. A default export will not be imported with curly brackets, but will be directly imported into a named identifier.
Exporting values with just the exports keyword is a quick way to export values from a module. You can use this keyword at the top or bottom, and all it does is populate the module. exports object. But if you're using exports in a file, stick to using it throughout that file.
Import. You can import modules into a file in two ways, based on if they are named exports or default exports. Named exports are constructed using curly braces. Default exports are not.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With