2

我尝试了各种选项,最后以以下混乱版本的 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"
  }
}
4

0 回答 0