【问题标题】:Run two instances of livereload at gulp在 gulp 运行两个 livereload 实例
【发布时间】:2015-09-22 17:33:58
【问题描述】:

我在开发过程中打开了 2 个选项卡(一个带有应用程序,第二个带有 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

Jasmine 测试套件有一行

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

而应用测试套件有这一行

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

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

【问题讨论】:

    标签: javascript gulp livereload gulp-livereload


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-11-22
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 2017-07-02
      • 1970-01-01
      • 2011-07-31
      • 2020-02-09
      • 1970-01-01
      相关资源
      最近更新 更多