TypeScript 编译器封装库

该封装库将 TypeScript 命令行编译器封装为易于使用的 JavaScript API,方便开发者在代码中直接调用。

安装

npm install typescript-compiler

使用示例

编译多个 TypeScript 文件:

const tsc = require('typescript-compiler');

tsc.compile(['a.ts', 'b.ts'], ['--out', 'out.js']);

编译 TypeScript 字符串:

const tsc = require('typescript-compiler');

const js = tsc.compileString('class TSC { awesome: boolean = true; }');

编译多个 TypeScript 字符串:

const tsc = require('typescript-compiler');

const result = tsc.compileStrings({
  'ship.ts': 'module Navy { export class Ship {} }',
});
zip 文件大小:505.57KB