Chr*_*row 5 module angularjs typescript angular
在 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 Build > Module system”下还有一个“System”选项,这显然与 tsconfig.json 中的“System”指代相同。
是的,它指的是 SystemJS,如果您希望 TypeScript 编译器按照您的预期运行并生成您预期的代码,那么显式包含它非常重要。如果您不指定,TypeScript 将恢复为基于当前targetES 版本生成(并期望)代码(默认情况下ES3,触发commonjs模块)。moduleResolution正如编译器文档中所述,它将对其他默认编译器选项(例如和 )产生影响allowSyntheticDefaultImports。
例如,如果您有一个如下所示的打字稿文件
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 版本或其他标志而有所不同。
| 归档时间: | 
 | 
| 查看次数: | 1347 次 | 
| 最近记录: |