如何让livereload与Gulp和Ripple Emulator一起工作?

时间:2014-10-21 07:55:57

标签: android cordova gulp ripple gulp-livereload

我尝试了各种选项,最后以gulpfile.js的以下混乱版本结束,但我无法让它工作:(。

我使用的是ripple-emulator npm包而不是Chrome插件。这确实启动了模拟器,除了livereload(手动刷新工作)之外,一切正常。

var gulp = require('gulp');
var path = require('path');
var o = require('open');
var ripple = require('ripple-emulator');
var connect = require('gulp-connect');
var injectReload = require('gulp-inject-reload');
var webPath = function(p) {
  return path.join('./www/', p);
};

gulp.task('connect', function() {
  connect.server({
      root: 'www',
      livereload: true
  });
});

gulp.task('html', function() {
  gulp.src('./www/*.html')
    .pipe(injectReload({
        host: 'http://localhost'
    }))
    .pipe(gulp.dest(webPath('build')))
    .pipe(connect.reload());
});

gulp.task('watch', function() {
  gulp.watch(['./www/*.html'], ['html']);
});

// The default task
gulp.task('default', ['connect', 'watch'], function() {

  var options = {
    keepAlive: false,
    open: true,
    port: 4400
  };

  // Start the ripple server
  ripple.emulate.start(options);

  if (options.open) {
    o('http://localhost:' + options.port + '?enableripple=true');
  }
});

我正在使用的依赖...

// package.json

{
  "name": "servicepromobile",
  "version": "0.0.0",
  "dependencies": {},
  "devDependencies": {
    "gulp": "latest",
    "open": "latest",
    "ripple-emulator": "latest",
    "gulp-livereload": "^2.1.1",
    "connect-livereload": "^0.5.0",
    "tiny-lr": "^0.1.4",
    "gulp-connect": "^2.0.6",
    "gulp-inject-reload": "0.0.2"
  },
  "engines": {
    "node": ">=0.10.0"
  },
  "scripts": {
    "test": "grunt test"
  }
}

0 个答案:

没有答案