【问题标题】:gulpfile only running once with watchgulpfile 仅使用 watch 运行一次
【发布时间】:2017-07-09 17:21:55
【问题描述】:

我有这个作为我的 gulpfile.js:

'use strict';

var gulp = require('gulp');
var sass = require('gulp-sass');

gulp.task( 'default', ['sass'] );

gulp.task('sass', function () {
  return gulp.src('./sass/theme.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('./css'));
});

gulp.task('sass:watch', function () {
  gulp.watch('./sass/**/*.scss', ['sass']);
});

我工作并编译了 sass,但它停止运行而不是观看?我不太熟悉 gulp 的工作原理,因此非常感谢您的帮助!

控制台的输出如下:

[13:14:29] Using gulpfile ~/public_html/mysite/gulpfile.js                                                                                                               
[13:14:29] Starting 'sass'...                                                                                                                                                               
[13:14:31] Finished 'sass' after 1.2 s                                                                                                                                                      
[13:14:31] Starting 'default'...                                                                                                                                                            
[13:14:31] Finished 'default' after 15 μs 

【问题讨论】:

  • 您需要在您的default 任务中包含sass:watch 任务。将 tasks 添加到 default task 告诉 gulp 按时间顺序执行一系列任务。

标签: node.js gulp gulp-watch gulp-sass


【解决方案1】:

你还没有开始sass:watch任务。

gulp.task( 'default', ['sass', 'sass:watch'] );

【讨论】:

    猜你喜欢
    • 2020-02-19
    • 2015-05-28
    • 2019-06-01
    • 2022-12-24
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    相关资源
    最近更新 更多