javascript - Shorthand for exporting an import - Stack Overflow

I've been meaning to do this with BabelJS, however I'm not sure whether Babel or the specific

I've been meaning to do this with BabelJS, however I'm not sure whether Babel or the specifications support it at the moment.

Given Outer.js:

export default function() { }

The example below does not work.

export Outer from './Outer'

With CommonJS modules, this could be easily written as

exports.x = require('./x');

I've been meaning to do this with BabelJS, however I'm not sure whether Babel or the specifications support it at the moment.

Given Outer.js:

export default function() { }

The example below does not work.

export Outer from './Outer'

With CommonJS modules, this could be easily written as

exports.x = require('./x');
Share Improve this question edited Apr 1, 2015 at 12:40 srph asked Apr 1, 2015 at 7:16 srphsrph 1,33220 silver badges35 bronze badges 2
  • You can use: js export * from './Outer'; – Rico Sta. Cruz Commented Apr 1, 2015 at 8:46
  • Thanks! I just cleared things a bit by adding an additional info of what Outer.js may contain (a module.exports or export default). – srph Commented Apr 1, 2015 at 12:44
Add a ment  | 

2 Answers 2

Reset to default 4

As of April 3, 2015, the BabelJS team has released v5.0 3 days ago which includes support for the said shorthand as stated in their blog post.

Lee Byron's stage 1 additional export-from statements proposal pletes the symmetry between import and export statement, allowing you to easily export namespaces and defaults from external modules without modifying the local scope.

Exporting a default

export foo from "bar";

equivalent to:

import _foo from "bar";
export { _foo as foo };

Old Answer:

This export notation

export v from "mod";

does not supported in ES6 (look at supported examples in the specification), but it can be supported in ES7 (look at this proposal).

To achieve exactly the same result you must use import for now:

import Outer from './Outer';
export {Outer};

TypeScript 1.5 also supports the ES 2015 additional export-from statements syntax:

export { default as Injector } from './lib/Injector';

Which generates the following ES5:

var Injector_1 = require('./lib/Injector');
exports.Injector = Injector_1.default;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744331090a4568891.html

相关推荐

  • javascript - Shorthand for exporting an import - Stack Overflow

    I've been meaning to do this with BabelJS, however I'm not sure whether Babel or the specific

    8天前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信