在 Aurelia 中导入非模块化脚本 (linq.js)

Import non modular scripts (linq.js) in Aurelia

我对使用 import 关键字将定义全局变量的脚本导入 aurelia 有疑问。我们可以简单地导入模块,但是像 linq.js 这样定义全局变量 Enumerable 的脚本呢?是否可以执行该脚本来定义该名称空间?

我尝试执行 this blog post 中的步骤,但它只定义了非静态方法。所以我不能使用 Enumerable.from 方法。

这是包管理器 jspm 的问题。当你有一个导出全局的模块时,你需要在你的 jspm 配置文件中配置一个 shim,你可以在其中指定导出的全局的名称。

然而,在linq.js的情况下,它似乎确实使用了module.exports(我在配置中查看this source here), so it should just work out of the box. If it doesn't, try specifying the module format(cjs)。

像这样导入:

import Enumerable from 'linq';