【问题标题】:Configure Live Reload on a Ionic project based on the generator-gulp-angular基于 generator-gulp-angular 在 Ionic 项目上配置 Live Reload
【发布时间】:2016-11-11 02:41:27
【问题描述】:

我有一个 Ionic 1.3.1 项目,其架构基于旧但黄金的 generator-gulp-angular,我想在设备 (Android) 上启用 Live Reload

我的 gulp 配置路径如下所示:

exports.paths = {
  src: 'src',
  dist: 'www',
  tmp: '.tmp',
  e2e: 'e2e'
};

这意味着要在浏览器中运行项目,我使用gulp serve,而要在Android 设备中运行,我使用gulp build && ionic run android

我不能使用命令ionic run android --livereloadas described in the doc here,因为它会同步www 文件夹,其中(在gulp build 之后)我有缩小文件而不是源文件。

所以我想以某种方式将两个命令 gulp serveionic run android --livereload 混合起来,但我真的不知道如何实现这一点。

【问题讨论】:

标签: android angularjs ionic-framework gulp gulp-livereload


【解决方案1】:

我解决了更新我的gulp watch 任务的问题,每次发生更改时它都会在命令ionic run android --livereload 运行时运行gulp build

我在gulp watch 中添加了一个标志--livereload,所以我的/gulp/watch.js 文件看起来像:

gulp.task('watch', ['inject'], function () {

  var livereload = process.argv.length === 4 && process.argv[3] === '--livereload';

  gulp.watch([path.join(conf.paths.src, '/*.html'), 'bower.json'], ['inject-reload']);

  gulp.watch([
    path.join(conf.paths.src, '/app/**/*.css'),
    path.join(conf.paths.src, '/app/**/*.scss'),
    path.join(conf.paths.src, '/scss/*.scss')
  ], function(event) {
    if (livereload) {
      gulp.start('build');
    } else {
      if(isOnlyChange(event)) {
        gulp.start('styles-reload');
      } else {
        gulp.start('inject-reload');
      }
    }
  });

  gulp.watch(path.join(conf.paths.src, '/app/**/*.js'), function(event) {
    if (livereload) {
      gulp.start('build');
    } else {
      if(isOnlyChange(event)) {
        gulp.start('scripts-reload');
      } else {
        gulp.start('inject-reload');
      }
    }
  });

  gulp.watch(path.join(conf.paths.src, '/app/**/*.html'), function(event) {
    if (livereload) {
      gulp.start('build');
    } else {
      browserSync.reload(event.path);
    }
  });
});

使用方法:

在终端选项卡上:

ionic run android --livereload

并且,在另一个终端选项卡上:

gulp watch --livereload

享受吧!

【讨论】:

    猜你喜欢
    • 2017-12-21
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    相关资源
    最近更新 更多