I have started using watchify in my gulp build recently, but i don't understand, why it doesn't throw an errors in terminal, when something is wrong. Probably, i should add something like if(err) throw err
somewhere, but i don't understand where exactly.
Also, this code suppose to do kind of hot reload, but it doesn't, it just building much faster than without watchify, but it reloads page anyway.
gulp.task('js', function() {
var bundler = browserify({
entries: ['src/js/main.js'], // Only need initial file, browserify finds the deps
transform: [babelify], // We want to convert JSX to normal javascript
debug: true, // Gives us sourcemapping
cache: {}, packageCache: {}, fullPaths: true // Requirement of watchify
});
var watcher = watchify(bundler);
return watcher
.on('update', function () { // When any files update
var updateStart = Date.now();
console.log('Updating!');
watcher.bundle() // Create new bundle that uses the cache for high performance
.pipe(source('main.js'))
// This is where you add uglifying etc.
.pipe(gulp.dest('dist'));
console.log('Updated!', (Date.now() - updateStart) + 'ms');
})
.bundle() // Create the initial bundle when starting the task
.pipe(source('main.js'))
.pipe(gulp.dest('dist'));
});