Javascript ES6`从导入导出*?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38077164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ES6 `export * from import`?
提问by Jordan Feldstein
Is there a syntax using ES6 or ES7 or babel which will allow me to easily bundle together many groups of sub files?
是否有使用 ES6 或 ES7 或 babel 的语法可以让我轻松地将多组子文件捆绑在一起?
E.g., given:
例如,给定:
./action_creators/index.js
./action_creators/foo_actions.js
./action_creators/bar_actions.js
Have index.js import foo and bar actions, then re-export them, so I can
让 index.js 导入 foo 和 bar 动作,然后重新导出它们,这样我就可以
import {FooAction, BarAction} from './action_creators/index.js'
I don't want to have to remember / change references if I were to change which file I've organized the objects themselves into.
如果我要更改将对象本身组织到哪个文件中,我不想必须记住/更改引用。
回答by Timo
Yes, ES6 supports directly exporting imported modules:
是的,ES6 支持直接导出导入的模块:
export { name1, name2, …, nameN } from …;
export {FooAction, BarAction} from './action_creators/index.js'
You can also re-export all exportsof the imported module using the *
syntax:
您还可以使用以下语法重新导出导入模块的所有导出*
:
export * from …;
export * from './action_creators/index.js';
回答by Gerson Diniz
Defaultexport as Default:
默认导出为Default:
export {default} from './something';
Defaultexport as Named:
默认导出为Named:
export {default as foo} from './something';
Namedexport as Default:
命名导出为默认:
export {foo as default} from './something';
Namedexport as Named:
命名导出为Named:
export {foo} from './something';