ES6模块:重新导出为对象 [英] ES6 module: re-export as object

查看:248
本文介绍了ES6模块:重新导出为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有moduleA,它可以导出一些功能:

I have moduleA which exports some functions:

// moduleA.js
export function f1() {...}
export function f2() {...}

有什么方法可以重新导出moduleB中所有moduleA的输出,并使它看起来像一个对象:

Is there any way to re-export all exports of moduleA in moduleB and make it looks like one object:

// moduleB.js
export * as a from 'moduleA';  // pseudo code, doesn't work

这样我才能以这种方式使用它?

So that I can use it in this way?

// main.js
import {a} from 'moduleB';
a.f1();
a.f2();

推荐答案

尚不支持语法,但是有

The syntax is not supported yet but there is a proposal for it.

您现在可以将其与Babel.js一起使用,或直接执行以下操作:

You can use it now with Babel.js or simply do:

import * as a from '...';
export {a};

这篇关于ES6模块:重新导出为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆