【问题标题】:TypeScript config for compiling different *.ts files each with referenced files?用于编译不同 *.ts 文件的 TypeScript 配置,每个文件都带有引用文件?
【发布时间】:2017-04-27 14:58:06
【问题描述】:

我有一个这样的文件夹结构:

/ts
    /module1
        /partials
            partial1.ts
            partial2.ts
        module1.ts
        tsconfig.json
    /module2
        /partials
            partial1.ts
            partial2.ts
        module2.ts
        tsconfig.json

每个module1.tsmodule2.ts 文件都在顶部引用了导入。例如:

/// <reference path="partials/1.ts" />
/// <reference path="partials/2.ts" />

每个模块都有一个tsconfig.json,如下所示:

{
    "compilerOptions": {

    },
    "files": [
        "module1.ts"
    ],
    "exclude": [
        "node_modules"
    ]
}

我在项目根目录中还有一个“标准”tsconfig.json 文件,如下所示:

{
    "compilerOptions": {
        "module": "none",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "inlineSourceMap": true
    },
    "exclude": [
        "node_modules"
    ]
}

我想要输出的是每个模块的 js 文件,例如module1.jsmodule2.js。但是,我实际上将整个 ts 文件夹导出为 JS 文件。

引用的文件没有被处理成一个。相反,它们以与 ts 文件相同的文件夹结构输出。例如:

/build
    js/
        partials/
            partial1.js
            partial2.js
        module1.js

我正在使用 gulp 来编译我的 TypeScript。任务如下所示:

gulp.task("ts", function() {
    tsProject.src()
        .pipe(sourcemaps.init())
        .pipe(tsProject(reporter)).js
        .pipe(sourcemaps.write())
        .pipe(gulp.dest("./build/js"));
});

我应该如何重新配置​​我的项目以达到预期的效果?

【问题讨论】:

    标签: typescript gulp


    【解决方案1】:

    尝试在 system.config 文件中添加 'isolatedModules': true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-29
      • 2015-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多