需要 EcmaScript 6 模块,它是如何工作的?

EcmaScript 6 module requiring, how does it work?

所以我知道如何在 ES6 中引入和导出模块。但是对于像 Aurelia 这样的框架,文档说你需要 aurelia 像这样:

import {LogManager} from 'aurelia-framework';

我是否必须将名为 aurelia-framework 的 JS 文件放在我正在执行它的 JS 文件所在的文件夹中,或者 import 函数是否与 [=14] 类似=] NodeJS/CommonJS?

中的函数

根据this article ES6 modules spec only deals with loading modules that are present in the file path. Downloading these files (via NPM or by other means) is outside of scope of ECMAScript 6 modules spec。规范中没有说明支持 npm 包包括(将目录结构向下遍历到 /,一次一个目录,查找 package.json 文件,然后在 node_modules 中搜索package.json 文件所在的目录)。因此,虽然 import 语法类似于 commonJS 样式,但不包括在 node_modules 目录中查找模块的全部魔法。

因此,要使您的示例生效,aurelia-framework 必须是文件系统中某处的 javascript 文件,并且它应该包含 exports 语句。

import {LogManager} from 'aurelia-framework'; // ./aurelia-framework.js
import {LogManager} from '../libs/aurelia-framework'; // ../libs/aurelia-framework.js

Aurelia, you can install dependent libraries using jspm. you can see an example of that here。 jspm 将为您获取包并将它们放入项目的子文件夹中。 jspm 使用索引(存储在 config.js 中)来知道在哪里找到文件(类似于 requirejs,但适用于 amd、commonjs 和 es6 模块)。

还有an example of using the aurelia libraries with requirejs amd loader. this example uses a bundle of aurelia libraries generated by r.js as shown here