Javascript 如何将commonjs上的所有变量从不同的文件导出到一个位置
我有包含文件的文件夹,每个文件都有如下导出模块 myFirst.jsJavascript 如何将commonjs上的所有变量从不同的文件导出到一个位置,javascript,commonjs,Javascript,Commonjs,我有包含文件的文件夹,每个文件都有如下导出模块 myFirst.js const myName=()=>({name:"helo"}) const myAddress=()=>({address:"Bali"}) module.export={ myName, myAddress } mySecond.js const myBisnis=()=>({name:"mouse bisnis"}) mod
const myName=()=>({name:"helo"})
const myAddress=()=>({address:"Bali"})
module.export={
myName,
myAddress
}
mySecond.js
const myBisnis=()=>({name:"mouse bisnis"})
module.export ={
myBisnis
}
myFirst.js和mySecond.js中的所有模块
const myBisnis=()=>({name:"mouse bisnis"})
module.export ={
myBisnis
}
myLast.js
module.export={
myFirst,
mySecond
}
当我调用myLast.js时
它将包含myFirst.js和secode.js中的所有模块
感谢您的重播如果要导出文件中不存在的函数或内容,请先导入。像这样:
//myLast.js
import firstModule from 'myFirst.js';
import secondModule from 'mySecond.js';
module.export = {
firstModule,
secondModule
};
或者您可以使用直接导出:
// myLast.js
export { myName, myAddress } from 'myFirst.js';
export { myBisnis } from 'mySecond.js';