Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp with watchify/browserify runs twice then stops watching

Here is my gulpfile.js

var gulp = require('gulp');
var browserify = require('browserify');
var source = require("vinyl-source-stream");
var reactify = require("reactify");
var watchify = require('watchify');
var gutil = require('gulp-util');

var paths = {
    scripts: ['src/jsx/index.jsx']
};

gulp.task('browserify', function(){


    var bundler = watchify(browserify('./src/jsx/index.jsx', watchify.args));
    bundler.transform(reactify);

    bundler.on('update', rebundle);

    function rebundle() {
        return bundler.bundle()
            // log errors if they happen
            .on('error', gutil.log.bind(gutil, 'Browserify Error'))
            .pipe(source('bundle.js'))
            .pipe(gulp.dest('./public/js'));
    }

    return rebundle();

});

gulp.task('watch', function() {
    gulp.watch(paths.scripts, ['browserify']);
});

Then my commandline output looks like this:

$ gulp watch

[15:10:41] Using gulpfile ~/blizztrack/dashboard/gulpfile.js
[15:10:41] Starting 'watch'...
[15:10:41] Finished 'watch' after 9.95 ms

save index.jsx

[15:10:45] Starting 'browserify'...
[15:10:51] Finished 'browserify' after 5.33 s

save index.jsx the second time

[15:11:08] Starting 'browserify'...
[15:11:10] Finished 'browserify' after 2.02 s

save index.jsx the third time

No output.

This seems to be doing exactly what I want it to the first two times, and then it just stops watching. Can anyone point me in the right direction?

like image 795
thealexbaron Avatar asked Dec 02 '14 22:12

thealexbaron


1 Answers

Just came across this issue. After browsing the web for answers for a couple hours I tried editing the file in Notepad instead of PHPStorm IDE. It turned out that browserify/watchify continued to work via notepad.

Thats when I tried to play around with some settings. It turned out PHPStorm / System Settings / Use "safe write", if enabled, stops watchify after PHPStorm edits the file.

All the problems magically disappeared when i turned "safe write" off. I am not sure what IDE you are using, but maybe there is a "Safe Write" option too.

like image 129
Jeremy Avatar answered Oct 11 '22 12:10

Jeremy