在 tsconfig.json 文件中,可以将以下选项指定为 compilerOptions 'module' 属性的值:
System
这样我们得到:
{
"compilerOptions": {
"module": "System",
...
System 是否引用 SystemJS(即,如果 SystemJS 被用作模块加载器,我在创建 AngularJS 或 Angular 应用程序时是否总是需要在我的 tsconfig.json 中使用“System”)?文档似乎没有对此进行解释:
https://www.typescriptlang.org/docs/handbook/compiler-options.html
在 TypeScript 的 Visual Studio 项目配置中,“TypeScript 构建 > 模块系统”下还有一个“系统”选项,这显然与 tsconfig.json 中的“系统”指的是同一事物。
最佳答案
是的,它指的是 SystemJS,如果您希望 TypeScript 编译器按照您的预期运行并生成您期望的代码,那么明确包含它很重要。如果您不指定,TypeScript 将恢复为基于当前 target
ES 版本(默认 ES3
,触发 commonjs
模块)。正如编译器文档中所述,它会影响其他默认编译器选项,例如 moduleResolution
和 allowSyntheticDefaultImports
。
例如,如果你有一个如下的 typescript 文件
import { functionA } from './moduleA';
functionA();
如果您将 module
指定为 system
,您生成的代码将使用系统调用:
System.register(["./moduleA"], function (exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var moduleA_1;
return {
setters: [
function (moduleA_1_1) {
moduleA_1 = moduleA_1_1;
}
],
execute: function () {
moduleA_1.functionA('Stuff');
}
};
});
但是,如果您允许编译器默认为 commonjs
,它将生成:
"use strict";
var moduleA_1 = require('./moduleA');
moduleA_1.functionA('Stuff');
请注意,生成的代码可能因 TS 版本或其他标志而异。
来自测试/经验和 module resolution和 compiler您链接的文档。
关于angularjs - tsconfig 模块选项 - 'System' 是指 SystemJS 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48142665/