typescript 打字稿 - 可以对整个文件夹运行 tsc 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35734366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:57:21  来源:igfitidea点击:

typescript - can tsc be run against an entire folder?

typescript

提问by Ciel

I'm pretty surprised this isn't in the docs that I could find - but is there any way to just tell tscto run against all files in a directory and its children without going through a whole tsconfig.jsonsetup?

我很惊讶这不在我能找到的文档中 - 但是有什么方法可以告诉tsc对目录中的所有文件及其子文件运行而不经过整个tsconfig.json设置?

采纳答案by Nathan Friend

Not that I know of. Using tscfrom the command line without a tsconfig.jsonrequires that you specify each file individually, like so:

从来没听说过。使用tsc命令行没有tsconfig.json要求您分别指定每个文件,就像这样:

tsc MyFile1.ts MyFile2.ts MyFile3.ts

However, it looks like you can simply create an empty tsconfig.json(i.e. just {}) at the root of your TypeScript directory and it will do what you want. From https://github.com/Microsoft/TypeScript/wiki/tsconfig.json:

但是,看起来您可以简单地在 TypeScript 目录的根目录创建一个空的tsconfig.json(即仅{}),它会做您想做的事情。来自https://github.com/Microsoft/TypeScript/wiki/tsconfig.json

If no "files"property is present in a tsconfig.json, the compiler defaults to including all TypeScript (*.ts or *.tsx) files in the containing directory and subdirectories.

如果 a 中不存在"files"属性tsconfig.json,则编译器默认将所有 TypeScript(*.ts 或 *.tsx)文件包含在包含目录和子目录中。

回答by Alexander Mills

You can use globs

你可以使用球

tsc x/file1.ts x/file2.ts x/file3.ts

should be equivalent to

应该相当于

tsc x/*.ts

回答by Amado Saladino

If you have tsconfig.json file inside your project folder, you can directly type

如果你的项目文件夹中有 tsconfig.json 文件,你可以直接输入

tsc this command will compile all your ts files within the current folder, if you dun have tsconfig.json file, you can generate it by typing:'

tsc -init

tsc 此命令将编译当前文件夹中的所有 ts 文件,如果您没有 tsconfig.json 文件,则可以通过键入:'

tsc -init

回答by Teoman shipahi

This can be overkill, but I just wrote a PS function to use in VS Code as a task;

这可能有点矫枉过正,但我​​只是写了一个 PS 函数作为任务在 VS Code 中使用;

function CompileTypeScriptFiles($folder) {
    $tsFiles = Get-ChildItem $folder -Filter "*ts" -Recurse
    $tsFiles | ForEach-Object {
        $tsFile = $_.FullName;
        $options = $tsFile + " --outDir js --sourceMap"
        Start-Process "tsc" $options 
    }
}

回答by Qwertiy

Windows users need to use forloop:

Windows 用户需要使用for循环:

for %f in (./path/*.ts) do npx tsc "./path/%f" --lib es2018 --outDir ./path/bin

Don't forget to double %if using it inside of batfile:

%如果在bat文件中使用它,请不要忘记加倍:

for %%f in (./path/*.ts) do npx tsc "./path/%%f" --lib es2018 --outDir ./path/bin