Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用不基于根文件夹的VSCode运行gulp任务_Gulp_Visual Studio Code - Fatal编程技术网

尝试使用不基于根文件夹的VSCode运行gulp任务

尝试使用不基于根文件夹的VSCode运行gulp任务,gulp,visual-studio-code,Gulp,Visual Studio Code,这是我的task.json // A task runner configuration for gulp. Gulp provides a less task // which compiles less to css. { "version": "0.1.0", "command": "gulp", "isShellCommand": true, "tasks": [ { "taskName": "sfdcBuild"

这是我的task.json

// A task runner configuration for gulp. Gulp provides a less task
// which compiles less to css. 
{
    "version": "0.1.0",
    "command": "gulp",
    "isShellCommand": true,
    "tasks": [
        {
            "taskName": "sfdcBuild",
            // Make this the default build command.
            "isBuildCommand": true,
            // Show the output window only if unrecognized errors occur.
            "showOutput": "always",
            // Use the standard less compilation problem matcher.
            "problemMatcher": "$lessCompile"
        }
    ]
}
不幸的是,我的gulp安装(本地安装)不在根目录下,而是在另一个文件夹中:

root/js/
那么,如何定义我希望从另一个文件夹中运行这个gulp命令呢

PS:将task.json移动到子文件夹中也不起作用。

此时不支持使用不同的
cwd启动任务。一种解决方法是在工作区的根文件夹中创建一个调用正确的
gulp
gulp.cmd或
gulp.sh
文件。例如,
gulp.cmd

@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node  "%~dp0\node_modules\gulp\bin\gulp.js" %*

为了避免将其提交到git存储库,您可以在
中忽略它。git/info/exclude

部分支持使用不同的工作目录。它不适用于自动检测gulp任务,但应该适用于运行gulp。您可以将类似的内容添加到顶级作用域中的tasks.json中

"options": {
    "cwd": "${workspaceRoot}/mySubDir"
},

但是,这仍然假设可以从该目录访问gulp和guld需要的所有节点模块。

您可以将
gulpfile.js的路径传递到
args中的gulp

"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
    "--gulpfile",
    "./js/gulpfile.js"
]

如果在linux中使用
make
命令时遇到同样的问题,因为Makefile存储在另一个位置,并且
make-f DIR/Makefile
由于某些其他原因无法工作。我试图编写一个bash脚本来更改目录并从那里调用命令,但是在linux中,从VSCode中运行脚本时发生了一些奇怪的事情。我犯了一个错误,最初使用了
${cwd}
而不是
${workspaceRoot}
。经过数小时的调试,为什么我总是遇到“超过最大堆栈大小”的错误,我意识到这不是一个吞咽问题,而是tasks.json问题。(因为cwd是递归设置的)有人知道如何使VS代码自动检测吞咽任务不在根目录中吗?我希望有一种方法可以让你喝啤酒。我花了很多时间试图解决这个问题。它现在也自动检测。我有同样的问题,但这不起作用,你知道为什么吗?(我已经贴了)