如何在一个tasks.json中定义多个打字稿编译任务? [英] How to define several typescript compile tasks in one tasks.json?

查看:31
本文介绍了如何在一个tasks.json中定义多个打字稿编译任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 VS Code 中为我的打字稿项目定义不同的构建任务.只要只有一项任务,我的 tasks.json 就可以工作.

I am trying to define different build tasks for my typescript project in VS Code. My tasks.json works as long as there is only one task.

tasks.json(命令面板 > 任务 tsc)

tasks.json (command pallette > task tsc)

{
"version": "0.1.0",
"command": "tsc",
"showOutput": "silent",
"args": ["-p", "."],
"problemMatcher": "$tsc"
"isShellCommand": true
}

当我定义多个任务时,我可以从命令面板中选择它们,但是它们会产生以下错误:

When I define several tasks, I can select them from the command palette, but they generate the following error:

TS5042:选项project"不能与命令行中的源文件混合

tasks.json(命令面板 > 任务执行)

tasks.json (command pallette > task dosomething)

{
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"tasks":[
    {
        "taskName":"dosomething",
        "showOutput": "silent",
        "args": ["-p", "."],
        "problemMatcher": "$tsc"
    },
    {
        "taskName":"compileandwatch",
        "showOutput": "silent",
        "args": ["-p", ".", "-w"],
        "problemMatcher": "$tsc"
    }
]
}

问题:如何在tasks.json中定义多个任务?哪些参数应该包含在任务"中,哪些应该在根中?microsoft docs 中没有示例.

Question: how to define several tasks in tasks.json? Which parameters should be included in "tasks" and which should be in the root? There is no example in the microsoft docs.

我尝试将args"留空:

I tried leaving "args" empty:

"args": [],

但后来我收到此错误dosomething.ts"未找到

But then I get this error "dosomething.ts" not found

推荐答案

我想你忘记在每个任务上设置 suppressTaskName = true.下面是一个对我有用的 tasks.json 的例子.请注意,这样 args 定义了应该运行的内容和传递给它的参数,任务名称不会影响结果命令:

I think you forgot to set suppressTaskName = true on each task. Below is an example of tasks.json that works for me. Note that this way the args define both what should be run and what parameters passed to it, task name does not affect resulting command:

{
    "version": "0.1.0",
    "command": "node",
    "windows": {
        "command": "node.exe"
    },
    "isShellCommand": true,
    "tasks": [
        {
            "taskName": "build.dev",
            "args": ["${workspaceRoot}/node_modules/gulp/bin/gulp.js", "build.dev"],
            "isBuildCommand": true,
            "suppressTaskName": true,
            "problemMatcher": [
                "$tsc"
            ]
        },
        {
            "taskName": "document.code",
            "args": ["${workspaceRoot}/node_modules/gulp/bin/gulp.js", "document.code"],
            "suppressTaskName": true,
            "problemMatcher": []
        },
        {
            "taskName": "start.specs.web.server",
            "args": ["${workspaceRoot}/node_modules/http-server/bin/http-server",
                    "${workspaceRoot}/dist/dev/specs"],
            "suppressTaskName": true,
            "problemMatcher": []
        }        
    ]
}

希望这会有所帮助.

这篇关于如何在一个tasks.json中定义多个打字稿编译任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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