我正在尝试使用 Typescript 设置 VSC,但我无法让 VSC 使用 Ctrl + Shift + B 编译所有 *.ts 文件。
我已经阅读了许多关于如何使用 VSC 设置 Typescript 的教程,但我没有成功。
我的 tsconfig.json 文件(位于根目录)如下所示:
{
"compilerOptions": {
"target": "ES5",
"module": "amd",
"sourceMap": true,
"outFile": "all.js"
}
}
和 tasks.json 文件(位于 root/.vscode 中):
{
"version": "0.1.0",
"command": "tsc", // it should be tsc.cmd instead of tsc
"isShellCommand": true,
"showOutput": "silent",
"args": [ ],
"problemMatcher": "$tsc"
}
当我输入 "args": ["${file}"] 时,它会编译当前文件,不是在 all.js 中,而是在 typescript-file-name.js 中,就像它忽略 tsconfig 文件一样。
VSC 可以使用自己的任务运行器编译所有 *.ts 文件吗?如何设置?
更新
正如我所说,我已经尝试过很多教程,说要将 args 留空,放置“-p”,“。”在其中,使用 npm install -g typescript,检查路径变量……这些都不起作用。
缺少的是 tasks.json 中的 tsc.cmd 命令。
如果有人知道,我想知道为什么它不能与 "command": "tsc"一起工作,即使在该命令行的 tasks.json 文件中的注释也是如此:
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
最佳答案
我相信您应该像这样更改 args 命令。
请注意,我将命令更改为指向本地 tsc 版本,但这并不重要。重要的东西在 args
选项中:["-p", "."]
{
"version": "0.1.0",
"command": "${cwd}/node_modules/.bin/tsc.cmd",
"isShellCommand": true,
"showOutput": "silent",
"args": ["-p", "."],
"problemMatcher": "$tsc"
}
关于typescript - Visual Studio Code 未编译所有 *.ts 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36643684/