How to start Gulp watch task when I type npm start
I have something like this in one of my projects. Note that it will background both processes - you can use ps
to get the ID and stop it with kill <pid>
.
"scripts": {
"start": "{ gulp watch & node server.js & }"
}
To disable logging, too:
"scripts": {
"start": "{ gulp watch --silent & node server.js & }"
}
You could run your server from your gulpfile:
var child = require('child_process');
var fs = require('fs');
gulp.task('default', ['server', 'watch']);
gulp.task('server', function() {
var server = child.spawn('node', ['server.js']);
var log = fs.createWriteStream('server.log', {flags: 'a'});
server.stdout.pipe(log);
server.stderr.pipe(log);
});
gulp.task('watch', function(){
gulp.watch(productionScripts, ['autoConcat']);
});
Then change your npm start
definition to look like:
"scripts": {
"start": "gulp"
}
You could concatenate multiple tasks in your start
in package.json
using the package concurrently
as such:
{
"start": "concurrent \"node server.js\" \"gulp\" "
}
And run npm start
from your terminal. This would execute all statements within start
.
For references: https://www.npmjs.com/package/concurrently
EDIT:
As pointed out by @Josh in the comments, the CLI name now matches the package name. Hence, you could write the script as:
{
"start": "concurrently \"node server.js\" \"gulp\" "
}