使用`tsc`为输出模块命名

时间:2018-02-13 21:08:08

标签: typescript typescript2.0 tsc

我使用这个命令:

tsc --out foo.js values/java-junit/*.ts --module amd

tsc --out foo.js values/java-junit/*.ts --module system

我得到了

define("index", ["require", "exports"], function (require, exports) {
    "use strict";
    exports.__esModule = true;
    var CodeGenerator = /** @class */ (function () {
        function CodeGenerator() {
            this.rawCode = '';
            this.styledCode = '';
        }
        // ...
        CodeGenerator.pluginName = 'java-junit';
        return CodeGenerator;
    }());
    exports.CodeGenerator = CodeGenerator;
});

System.register("index", [], function (exports_1, context_1) {
    "use strict";
    var __moduleName = context_1 && context_1.id;
    var CodeGenerator;
    return {
        setters: [],
        execute: function () {
            CodeGenerator = /** @class */ (function () {
                function CodeGenerator() {
                    this.rawCode = '';
                    this.styledCode = '';
                }
                 // ...
                CodeGenerator.pluginName = 'java-junit';
                return CodeGenerator;
            }());
            exports_1("CodeGenerator", CodeGenerator);
        }
    };
});

我的问题是 - 有没有办法用命令行选项命名模块,而不是模块名称为“index”?

1 个答案:

答案 0 :(得分:1)

您可以使用包含文件顶部的amd-module directive命名您的模块:

/// <amd-module name="NamedModule"/>
export function foo() { }

将生成:

define("NamedModule", ["require", "exports"], function (require, exports) {
    function foo() { }
    exports.foo = foo;
});