本文介绍了ES6`从导入导出*?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有使用 ES6 或 ES7 或 babel 的语法可以让我轻松地将多组子文件捆绑在一起?

Is there a syntax using ES6 or ES7 or babel which will allow me to easily bundle together many groups of sub files?

例如,给定:

./action_creators/index.js
./action_creators/foo_actions.js
./action_creators/bar_actions.js

让 index.js 导入 foo 和 bar 动作,然后重新导出它们,这样我就可以

Have index.js import foo and bar actions, then re-export them, so I can

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.

推荐答案

是的,ES6支持直接导出导入的模块:

export { name1, name2, …, nameN } from …;

export {FooAction, BarAction} from './action_creators/index.js'

您还可以使用 * 语法重新导出导入模块的所有导出:

export * from …;

export * from './action_creators/index.js';

有关 MDN 的更多信息.

这篇关于ES6`从导入导出*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 13:57