如何在gulpfile中抛出错误?

时间:2015-09-26 08:57:23

标签: gulp watchify

我最近开始在我的gulp版本中使用了watchify,但是我不明白,为什么当出现问题时它不会在终端中抛出错误。也许,我应该在某个地方添加类似if(err) throw err的内容,但我不明白到底在哪里。

此外,这段代码假设要进行热重新加载,但它没有,它只比没有watchify的构建速度快得多,但无论如何都会重新加载页面。

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'));
});

0 个答案:

没有答案