javascriptgulplivereloadgulp-livereload

Run two instances of livereload at gulp


I have 2 tabs opened at development process (one with application, second one with jasmine test suite).

So, I have 2 browserify bundles (which are seems like this code), so, I need two gulp-livereload instances worked. This is how I do that:

var livereloadTestSuite = require('gulp-livereload');
var livereloadDeveloperSuite = require('gulp-livereload'); // port 35728

    appBundler.bundle()
      .on('error', gutil.log)
      .pipe(source('application.js'))
      .pipe(gulpif(!options.development, streamify(uglify())))
      .pipe(gulp.dest(options.dest))
      .pipe(gulpif(options.development, livereloadDeveloperSuite())) // this line
      .pipe(notify(function () {
        console.log('APP bundle built in ' + (Date.now() - start) + 'ms');
      }));

  testBundler.bundle()
    .on('error', gutil.log)
    .pipe(source('specs.js'))
    .pipe(gulp.dest('./build/'))
    .pipe(livereloadTestSuite())
    .pipe(notify(function () {
      console.log('TEST bundle built in ' + (Date.now() - start) + 'ms');
    }));

gulp.task('default', ['buildDependencies'], function () {
  livereloadTestSuite.listen();
  livereloadDeveloperSuite.listen({ port: 35728, host: 'localhost' });

  // calling bundler & testBundler methods

And the jasmine test suite has the line

<script src="http://localhost:35729/livereload.js?snipver=1"></script>

And app test suite has this line

<script src="http://localhost:35728/livereload.js?snipver=1"></script>

Jasmine test suite reloads successful on it's rebundle, but development suite doesn't reload at all. I don't know how to solve this issue


Solution

  • Done using remove cache of the required nodejs module:

    var livereloadTestSuite = require('gulp-livereload');
    delete(require.cache[require.resolve('gulp-livereload')]);
    var livereloadDeveloperSuite = require('gulp-livereload');