簡體   English   中英

Gulp 4 Watch Task,僅運行一次

[英]Gulp 4 Watch Task, run only one time

我在使用Gulp 4時遇到了麻煩。當我檢測到更改時,我的html文件內部只運行一次watch任務。

我的錯誤在哪里? 請幫助我修復我的gulpfile

這是我的代碼:

var gulp            = require('gulp'),
    sass            = require('gulp-sass'),
    cleanCSS        = require('gulp-clean-css'),
    autoprefixer    = require('gulp-autoprefixer'),
    rename          = require('gulp-rename'),
    inject          = require('gulp-inject'),
    uglify          = require('gulp-uglify'),
    concat          = require('gulp-concat'),
    plumber         = require('gulp-plumber'),
    babel           = require('gulp-babel'),
    browserify      = require('gulp-browserify'),
    clean           = require('gulp-clean'),
    sourcemaps      = require('gulp-sourcemaps'),
    htmlmin         = require('gulp-html-minifier'),
    browserSync     = require('browser-sync');


var src             = './src/',
    dist            = './dist/';


//####################################
// MINIFY HTML
gulp.task('html', function(){
    gulp.src(dist + '*.html', {force: true})
        .pipe(clean());
    gulp.src(src + '*.html')
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest(dist));
});

//####################################
// WATCH
gulp.task('default', function(){
    gulp.watch([src + '*.html'], gulp.series('html'));
});

當我手動運行html-task時,出現以下警告:

The following task did not complete: html Did you forget to signal async completion?

我也該如何解決這個問題?

我在html文件中通過代碼更改解決了我的問題:

gulp.task('html', done => {
    gulp.src(dist + '*.html', {force: true})
        .pipe(clean());
    gulp.src(src + '*.html')
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest(dist));
    done();
});

監視任務現在可以正常工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM