Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to run a gulp task with VSCode which is not based in the root folder

Tags:

This is my 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"         }     ] } 

Unfortunately my gulp installation (the local one) is not under root but inside another folder:

root/js/ 

so how can I define that I would like to run this gulp command from inside the other folder?

PS: moving the task.json into the subfolder did nor work.

like image 665
Florian Hoehn Avatar asked May 01 '15 22:05

Florian Hoehn


People also ask

How do I run a gulp file in Visual Studio Code?

Run a Gulp Task in Visual Studio CodeType "Run Task" and select it, which will bring up a list of tasks configured in Gulp. Choose the Gulp Task you want to run! Most of your Gulp Tasks will probably be automated using gulp watch, but manual Gulp Tasks can easily be run within Visual Studio Code.

How do I add gulp to Visual Studio?

To do this, right click project > Add New Item.. Select Web node and select npm Configuration file and click Add. Next, we will create gulp tasks to minimize html and javascript files in our solution. To do this, we need to install gulp-htmlclean and gulp-uglify plugins from command prompt using the below commands.

How do I run a task in VS Code?

Tip: You can run your task through Quick Open (Ctrl+P) by typing 'task', Space and the command name. In this case, 'task lint'.

How do I change the directory in VS Code?

You can go to that specific directory or create shortcut to desktop then click right click on that folder and then click on open with code. If you didnot see open with code then reinstall your VS code and check on open with code when you are reinstalling VS Code.


2 Answers

Using a different working directory is partly supported. It doesn't work for auto detection of gulp tasks but it should work for running gulp. You can add something like this to the tasks.json in the top level scope

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

However this still assumes that gulp and all node modules guld requires are accessible from that directory.

like image 63
Dirk Bäumer Avatar answered Jun 15 '23 12:06

Dirk Bäumer


The tasks.json doesn't support at this time launching a task with a different cwd. One way to workaround it would be to create a gulp.cmd or gulp.sh file in your workspace's root folder that invokes the correct gulp. E.g. gulp.cmd:

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

To avoid committing this to your git repository, you could ignore it in .git/info/exclude

like image 24
Alex Dima Avatar answered Jun 15 '23 12:06

Alex Dima