【问题标题】:How to both build and compile typescript with tasks.json如何使用 tasks.json 构建和编译 typescript
【发布时间】:2016-09-12 21:57:34
【问题描述】:

我正在使用 Visual Studio Code (vscode),这是一个在 Visual Studio 2015 (VS Proper) 中初始化的 asp.net 核心项目。当我在 vscode 中设置它时,初始过程包括在 tasks.json 中添加这个自动生成的构建任务:

{
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "build",
            "args": [
                "${workspaceRoot}\\project.json"
            ],
            "isBuildCommand": true,
            "problemMatcher": "$msCompile"
        }
    ]
}

但我使用的是打字稿,所以我希望它能够编译。我在命令托盘中键入“配置任务运行程序”(仅在重命名 tasks.json 后,因为它创建了一个同名文件)并配置如下所示的打字稿任务:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "args": ["-p", "."],
    "showOutput": "silent",
    "problemMatcher": "$tsc"
}

然后,当我构建时,我的打字稿被很好地编译,但我没有得到真正的“构建”......

不起作用的直观解决方案:

{
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "build",
            "args": [
                "${workspaceRoot}\\project.json"
            ],
            "isBuildCommand": true,
            "problemMatcher": "$msCompile"
        },
        {
            "taskName": "tsc",
            "isBuildCommand": true,
            "args": ["-p", "."],
            "showOutput": "silent",
            "problemMatcher": "$tsc"

        }
    ]
}

如何在每次构建时同时执行这两个过程? 对我没有帮助的有希望的链接:

https://github.com/Microsoft/vscode/issues/981

How to define several typescript compile tasks in one tasks.json?

【问题讨论】:

    标签: visual-studio typescript asp.net-core visual-studio-code


    【解决方案1】:

    此功能请求仍处于打开状态,请参阅:https://github.com/Microsoft/vscode/issues/981

    解决此问题的最佳方法是使用任务运行器,如 grunt、gulp 甚至 npm 来运行不同的任务。然后,在 tasks.json 中,您可以按任务名称定义构建和测试命令,并为每个任务设置问题匹配器。

    【讨论】:

    • 嗯...我已经扫描了 issue/981 几次,但有点不知所措。您能否链接到通过 gulp 解决方案回答的相关 S/O 问题,甚至提供一个简短的示例?我对这一切有点陌生,不太确定像 { "taskName": "tsc" } 和 { "args": ["-p", "."] } 这样的魔术字符串如何最终调用我的打字稿编译器,也不知道如何通过 gulp 在构建时复制此操作(更好的是保存时)。不过,我对 gulp 有点熟悉,这就是我偏爱的原因。你可以用 npm 做到这一点吗?真的什么...
    猜你喜欢
    • 2020-05-05
    • 2020-09-03
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    相关资源
    最近更新 更多