如何查看和编译所有 TypeScript 源代码? [英] How to watch and compile all TypeScript sources?

查看:30
本文介绍了如何查看和编译所有 TypeScript 源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个宠物项目转换为 TypeScript,但似乎无法使用 tsc 实用程序来查看和编译我的文件.帮助说我应该使用 -w 开关,但它看起来不能递归地观察和编译某个目录中的所有 *.ts 文件.这似乎是 tsc 应该能够处理的事情.我有哪些选择?

I'm trying to convert a pet project to TypeScript and don't seem to be able to use the tsc utility to watch and compile my files. The help says I should use the -w switch, but it looks like it can't watch and compile all *.ts files in the some directory recursively. This seems like something tsc should be able to handle. What are my options?

推荐答案

在您的项目根目录中创建一个名为 tsconfig.json 的文件,并在其中包含以下几行:

Create a file named tsconfig.json in your project root and include following lines in it:

{
    "compilerOptions": {
        "emitDecoratorMetadata": true,
        "module": "commonjs",
        "target": "ES5",
        "outDir": "ts-built",
        "rootDir": "src"
    }
}

请注意outDir为接收编译后的JS文件的目录路径,rootDir为目录路径包含您的源 (.ts) 文件.

Please note that outDir should be the path of the directory to receive compiled JS files, and rootDir should be the path of the directory containing your source (.ts) files.

打开终端并运行tsc -w,它会将src目录中的任何.ts文件编译成.js 并将它们存储在 ts-built 目录中.

Open a terminal and run tsc -w, it'll compile any .ts file in src directory into .js and store them in ts-built directory.

这篇关于如何查看和编译所有 TypeScript 源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆