I have a gulp.js file that includes:
gulp.task('default', ['watch']);
Which starts up the watch task
gulp.task('watch', function(){
gulp.watch(productionScripts, ['autoConcat']);
});
Then on any saved changes to files in productionScripts, the watch task will concat the files.
What I would like to do, is in my package.json, I would like to spool up this watch when I type npm start (this already starts my node server).
package.json
"start": "node server.js",
UPDATE--------
Ben(b3nj4m.com), I tried what you stated. The watch and server start up. However, everything runs twice (probably due to the editor, not related), but I do lose my server log when I start it up with gulp.
[15:31:18] Starting 'autoConcat'...
[15:31:18] Finished 'autoConcat' after 147 ms
[15:31:19] Starting 'autoConcat'...
[15:31:19] Finished 'autoConcat' after 138 ms
[15:31:20] Starting 'autoConcat'...
[15:31:20] Finished 'autoConcat' after 127 ms
[15:31:23] Starting 'autoConcat'...
It's like there is a loop between the server restarting on a change, and the concatenated file changing.
You could concatenate multiple tasks in your
start
inpackage.json
using the packageconcurrently
as such:And run
npm start
from your terminal. This would execute all statements withinstart
.For references: https://www.npmjs.com/package/concurrently
One best practice to consider is to use nodemon and gulp-nodemon and then like the accepted answer, trigger the gulp script from npm with
npm start
. It's blazing fast and you get the node server restarted on file changes. For example:gulpfile.js
package.json
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 withkill <pid>
.To disable logging, too:
You could run your server from your gulpfile:
Then change your
npm start
definition to look like: