如何在Visual Studio代码中运行TypeScript构建?

ruarlubt  于 2023-04-13  发布在  TypeScript
关注(0)|答案(1)|浏览(193)

我正在使用this文档在Visual Studio代码编辑器中运行hello-world类型脚本程序。
我已经做了以下步骤
1.安装了TypeScript编译器tsc --版本显示Version 4.2.4
1.将TypeScript转换为JavaScript
当我尝试运行类型脚本构建时,通过执行运行构建任务(B),我看不到任何要构建的任务。

所以我在这一点上卡住了。有人能告诉我,如果我们需要手动创建这个任务?还是有一个先决条件,我错过了?
谢谢!

0s0u357o

0s0u357o1#

尝试重新启动VSCode。如果不起作用,请尝试通过以下方式配置任务:
Command palette (Ctrl+Shift+P / F1) > Tasks: Configure default build task
如果这不起作用,这里是默认的任务配置:

{
    "version": "2.0.0",
    "tasks": [
        {  // For build
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ],
            "group": "build",
            "label": "tsc: build - tsconfig.json"
        },
        {  // For watch
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "option": "watch",
            "problemMatcher": [
                "$tsc-watch"
            ],
            "group": "build",
            "label": "tsc: watch - tsconfig.json"
        },
        { // If both of the above don't work you could create an npm script and run it via this task
            "type": "npm",
            "script": "build", // This should be the name of your script
            "problemMatcher": [],
            "label": "npm: build typescript"
        }
    ]
}

要检测到这些,请在工作区的根目录下创建一个.vscode文件夹,并在其中创建一个文件tasks.json。如果您将上面的json放入其中,VSCode将找到您的任务。

相关问题