【发布时间】:2015-02-13 19:28:01
【问题描述】:
如何连接 ES6 模块?
var foo = 2; // This would normally be scoped to the module.
export function Bar() {}
// ...concatenate...
import { Bar } from 'javascripts/bar' //This file no longer exists in the concatenated scenario.
export function Bam() {}
【问题讨论】:
-
//This file no longer exists in the concatenated scenario.是什么意思?您必须从文件中导入它,或者将其内容包含在内。您是否尝试在没有单独的文件来定义 Bar 的情况下导入 Bar? -
concat 是什么意思?创建导出两个模块项目的第三个文件有什么问题?
-
在当前的 ES6 语法中不可能在同一个文件中声明两个模块。这是否回答了您最初的问题?
-
等等,最后一个说法是错误的,
System.module刚刚从 ES6 中删除并放入了不同的规范 - 这让我很头疼:S -
@justin 我个人可以推荐 babel(以前是 6to5),它会很乐意在构建步骤中为您执行此操作 - 超级有用并生成非常好的代码。
标签: javascript module ecmascript-6 es6-modules