Reputation: 237
I'm trying to set my project's gulp tasks in order and this how my gulpfile.js code looks currently:
var gulp = require('gulp'),
nodemon = require('gulp-nodemon'),
webpack = require('gulp-webpack');
gulp.task('nodemon', ['webpack'], function(){
console.log('NODEMON');
return nodemon({
script: 'server/server.js',
ext: 'js',
ignore: [
'client/game.js'
],
tasks: function(changedFiles){
var tasks = ['webpack'];
changedFiles.forEach(function(file){
console.log('changed file: ' + file);
});
return tasks;
},
env: { 'NODE_ENV': 'development' }
});
});
gulp.task('webpack', function(){
console.log('WEBPACK');
return gulp.src('src/main.js')
.pipe(webpack({
entry: `${__dirname}/src/main.js`,
output: {
path: `${__dirname}/client/`,
filename: 'game.js'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
query: {
presets: ['es2015']
}
}
]
}
}))
.pipe(gulp.dest('client/'));
});
gulp.task('default', ['webpack', 'nodemon'], function(){
console.log('DEFAULT');
});
First of all, everything works and that's fine. But when I modify my server.js file, it always triggers the onChange event twice causing the 'webpack' run and the server restart twice. What am I doing wrong?
Edit: The strange thing is that every time I modify a script, not only does it trigger the 'webpack' task run as it's supposed to be, but it also re-runs my gulpfile.js script, duplicating every task it runs, which is why the server starts twice. My problem now is why would gulpfile.js be run all over each time. This doesn't happen if I skip the tasks parameter.
Upvotes: 2
Views: 235