是否有使用ES6或ES7或babel的语法允许我轻松地将许多子文件组捆绑在一起?
,例如:
./action_creators/index.js
./action_creators/foo_actions.js
./action_creators/bar_actions.js
让index.js导入foo和bar动作,然后重新导出它们,这样我就可以
import {FooAction, BarAction} from './action_creators/index.js'
如果我要更改我自己组织对象的文件,我不想记住/更改引用。
答案 0 :(得分:60)
是, ES6支持直接导出导入的模块:
export { name1, name2, …, nameN } from …;
export {FooAction, BarAction} from './action_creators/index.js'
您还可以使用*
语法重新导出导入模块的所有导出:
export * from …;
export * from './action_creators/index.js';
答案 1 :(得分:27)
默认导出为默认:
export {default} from './something';
默认导出为命名:
export {default as foo} from './something';
命名导出为默认:
export {foo as default} from './something';
命名导出为命名:
export {foo} from './something';
命名导出为重命名:
export {foo as bar} from './something';