I'm executing gulp.watch as part of a precompile script in a .NET Core project. When executing dotnet run the gulp.watch call seems to block the thread, so that the application won't start at all.
How can I tell gulp.watch to return the handle to the thread?
I have created a minimum working example to reproduce the problem using dotnet new and installing gulp via npm.
This is my gulpfile.js:
var gulp = require('gulp');
gulp.task('copy', () => {
gulp.src("watch_src/foo.txt")
.pipe(gulp.dest("watch_dst/"));
});
gulp.task('watch', () => {
var watcher = gulp.watch("watch_src/foo.txt", ['copy']);
watcher.on('change', function(){
console.log('foo.txt changed!');
});
});
gulp.task('default', ['watch']);
My Program.cs file looks like:
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
My project.json file looks like:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
},
"scripts": {
"precompile": "gulp"
}
}
Executing dotnet run will execute the precompile script and changes to foo.txt are reflected by the event handler on the console. But the Main method that should print Hello World! does not get executed:
c:\Temp\src\gulptest>dotnet run
Compiling gulptest for .NETCoreApp,Version=v1.0
[17:03:48] Using gulpfile c:\Temp\src\gulptest\gulpfile.js
[17:03:48] Starting 'watch'...
[17:03:48] Finished 'watch' after 11 ms
[17:03:48] Starting 'default'...
[17:03:48] Finished 'default' after 43 ╬╝s
foo.txt changed!
[17:04:15] Starting 'copy'...
[17:04:15] Finished 'copy' after 34 ms
I am using vs code and I've met the question as you too
In the project.json,you have the section:
"scripts": {
"precompile": "gulp"
}
which will stuck the dotnet run
Following these steps If you want to launch dotnet run and gulp watch
Step1: Define a new task in task.json file:
{
"type": "shell",
"command": "gulp watch",
"problemMatcher": [],
"label": "gulp-watch"
}
Step2: Add a new launch configuration in launch.json:
{
"name": "gulp-watch",
"preLaunchTask": "gulp-watch",
"request": "launch",
"type": "node"
},
Step3: Add compound configuration in the launch.json:
"compounds": [{
"name": ".Net+gulp",
"configurations": [
"gulp-watch",
".NET Core Launch (web)"
]
}],
For more detail,please refer to this link https://code.visualstudio.com/docs/editor/debugging
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With