【问题标题】:Compile TypeScript to multiple targets将 TypeScript 编译到多个目标
【发布时间】:2020-03-09 03:08:31
【问题描述】:

我想将 Typescript 文件编译为多个目标,例如 ES5 和 ES6。我有以下示例目录:

ES5

ES6

test.ts

tsconfig.json

因此,当我运行编译器时,我希望它将 test.ts 作为 ES5 编译到 ES5 文件夹,并将 ES6 编译到 ES6 文件夹。这有可能吗?

【问题讨论】:

  • 肯定有可能,你试过了吗?

标签: typescript ecmascript-6 ecmascript-5 tsconfig


【解决方案1】:

一个简单的解决方案是创建两个具有不同目标和输出目录的 tsconfig.json 文件。

tsconfig-es5.json

{
  "compilerOptions": {
    "target": "ES5",
    "outDir": "./ES5",
    // Additional configuration like module type etc.
}

tsconfig-es6.json

{
  "compilerOptions": {
    "target": "ES6",
    "outDir": "./ES6",
    // Additional configuration like module type etc.
}

然后创建一个连接建筑物的构建脚本,例如对于 Windows:

tsc --project ./tsconfig-es5.json && tsc --project ./tsconfig-es6.json

另一种方法是拥有一个 tsconfig.json 并在构建脚本中直接指定 targetoutDir 参数(请参阅 Compiler Options)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-26
    • 2017-01-22
    • 2016-06-17
    • 2019-02-27
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多