【问题标题】:Use Visual Studio Code Tasks with Gulp 4.0在 Gulp 4.0 中使用 Visual Studio Code 任务
【发布时间】:2018-01-03 02:46:30
【问题描述】:

我正在将项目从 Gulp 3.9.1 (npm install gulp) 切换到 Gulp 4.0 (npm install gulp-4.0.build),但是当我这样做时,Visual Studio Code 不再能够自动- 检测我的 gulpfile.js 中的任务。在这两种情况下,gulp 都安装在本地。

我的 .vscode/tasks.json 看起来像:

{
    "version": "0.1.0",
    "command": "gulp",
    "isShellCommand": true,
    "showOutput": "always"
}

查看任务输出,我看到以下消息:

运行 gulp --tasks-simple 没有列出任何任务。你运行 npm install 了吗?

您可以将 Gulp 4.0 与 VS Code 一起使用并让它自动检测任务吗?如果是这样,我需要按照哪些步骤进行设置?

【问题讨论】:

    标签: visual-studio-code vscode-tasks gulp-4


    【解决方案1】:

    是的,你可以使用 vscode 和 gulp4.0。我会看看how to upgrade to gulp4.0

    你是先卸载 gulp3.9.1 的吗?

    您还应该在本地和全局安装 gulp4.0

    然后运行

    gulp -v

    以确保它有效。 vsCode 应该在您的 tasks.json 文件和 gulpfile.js 中检测到这两个任务。您使用的是较旧的 tasks.json 版本 0.1.0。这是一个 tasks.json 文件的示例,它允许我从 workspaceRoot 的任何位置在命令行中键入“gulp sync”并运行该任务:

    {
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Start server and process files",
            "command": "gulp",
            "args": [
                "sync"
            ],
            "type": "shell",
            "options": {
                "cwd": "${workspaceRoot}"
            }
        }
    ]
    }
    

    它运行我在 gulpfile.js 中定义的“同步”任务。事实上,您可以为其分配一个热键组合,例如:

    { "key": "shift+escape",  
      "command": "workbench.action.tasks.runTask", 
      "args": "Start server and process files"
    },
    

    在您的 keybindings.json 中。

    【讨论】:

      猜你喜欢
      • 2018-11-02
      • 2016-05-21
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      • 2019-01-07
      • 2017-09-25
      • 1970-01-01
      相关资源
      最近更新 更多