joeyfigaro
1/25/2017 - 11:11 PM

Snippet for reloading gulp process when gulpfile.js is updated

Snippet for reloading gulp process when gulpfile.js is updated

//
// gulpfile.babel.js
//
import { spawn } from 'child_process';

function autoload() {
	let process;

	const spawnChildren = e => {
		if (process) process.kill();

		return process = spawn('gulp', 'default', { stdio: 'inherit' });
	}

	return gulp.watch(path.resolve(__dirname, 'gulpfile.babel.js'), spawnChildren);
}

gulp.task('autoload', autoload);
gulp.task('default', [...]);
                      
//
// Package.json
//
scripts: {
  "start": "gulp autoload"                      
}