【问题标题】:tsconfig.json and external referencestsconfig.json 和外部引用
【发布时间】:2016-03-15 19:07:23
【问题描述】:

我有一个使用打字稿的网络项目,并且我有以下(伪)文件结构:

.
|_externaldeps
|_tssrc
|_test
|_tsoutput
|_typings

externaldeps 包含外部库,例如 Angular、Jquery 等,还包含一些包含 d.ts 文件的公司内部库。

tssrc 包含我的源文件

test 包含用 Typescript 编写的业力测试。

tsoutput包含转译tssrc的结果

typings 包含来自 DefinetlyTyped 的 d.ts 文件

我的问题是如何为此配置 tsconfig.json。 tssrc 需要知道除了 test 文件夹之外的所有东西,test 文件夹基本上只需要知道 tssrc 文件夹等。

如何解决?非常感谢您的建议。

【问题讨论】:

  • 你能详细说明一下吗? “需要知道”是什么意思?也许this 是一个有用的帖子。

标签: typescript


【解决方案1】:

您应该使用像Gulp 这样的任务运行工具,从长远来看,它会让您的生活更轻松...

以下是用于使用 Gulp 编译一些单元测试和源代码的配置示例:

// The TypeScript compiler settings
var tsProject = tsc.createProject({
  removeComments : false,
  noImplicitAny : false,
  target : "ES5",
  module : "commonjs",
  declarationFiles : false
});

// compile app code
gulp.task("build-source", function() {
  return gulp.src(__dirname + "/source/*.ts")
             .pipe(tsc(tsProject))
             .js.pipe(gulp.dest(__dirname + "/build/source/"));
});

var tsTestProject = tsc.createProject({
  removeComments : false,
  noImplicitAny : false,
  target : "ES5",
  module : "commonjs",
  declarationFiles : false
});

// compile test code
gulp.task("build-test", function() {
  return gulp.src(__dirname + "/test/*.test.ts")
             .pipe(tsc(tsTestProject))
             .js.pipe(gulp.dest(__dirname + "/build/test/"));
});

注意:我使用两个分开的 ``tsc.createProject` 因为使用相同的两次不同的输入和输出文件夹会导致意外的行为。

完整示例可在here 获取。查看gulpfile.js 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    • 1970-01-01
    • 2019-11-16
    • 2018-10-11
    • 2017-07-07
    • 2020-12-29
    相关资源
    最近更新 更多