在gulp运行两个livereload实例

时间:2015-09-22 17:33:58

标签: javascript gulp livereload gulp-livereload

我在开发过程中打开了两个标签(一个带有应用程序,另一个带有jasmine测试套件。)

所以,我有2个browserify包(看起来像this code),因此,我需要两个gulp-livereload个实例。这就是我这样做的方式:

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

茉莉花测试套件有

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

app app套件有这一行

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

Jasmine测试套件重新加载成功,但是开发套件根本没有重新加载。我不知道如何解决这个问题

1 个答案:

答案 0 :(得分:0)

使用删除所需nodejs模块的缓存完成:

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