例如
File A
export const hello = {...something}
File B
// export name is same to File A
export const hello = {...another}
和Index.js
// want to import File A and File B's hello module like below
import { hello } from './File A', 'File B';
// Iterable like array, object or else
const mergedHello = hello;
我想从同一目录动态导入所有 hello
。
如果有 100 个带有 export hello
的文件,那么 100 行导入是很奇怪的...
这是可能的还是任何合适的模块?
我找不到合适的 js 模块..
答案 0 :(得分:0)
我认为这是不可能的,您可以创建另一个模块来导出所有其他模块:
export {hello as helloA} from './FileA'
export {hello as helloB} from './FileB'
...
然后在 Index
文件中,您可以像这样导入它们:
import * as hello from './module'
或者如果您想要其中的一些:
import {helloA, helloB} from './module'