简体   繁体   中英

GULP watch not working in my gulp.js file

Hi im trying to get a gulp watch on the go in my gulp.js file. It needs to run my sass and minify it and set to destination folder on watch. Can anybody help please?

var gulp = require('gulp');
    var sass = require('gulp-sass');
    var minifyCss = require('gulp-minify-css');
    var uglify = require('gulp-uglify');
    var watch = require('gulp-watch');
    var htmlmin = require('gulp-html-minifier');

    gulp.task('sass', function(){
      return gulp.src('scss/styles.scss')
        .pipe(sass()) // Converts Sass to CSS with gulp-sass
        .pipe(minifyCss())
        .pipe(gulp.dest('dest'))
    });


    gulp.task('minify-css', function() {
      return gulp.src('dest/*.css')
        .pipe(minifyCss())
        .pipe(gulp.dest('dest'));
    });

    gulp.task('compress', function() {
      return gulp.src('lib/*.js')
        .pipe(uglify())
        .pipe(gulp.dest('dist'));
    });

    gulp.task('minify-html', function() {
      gulp.src('*.html')
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest(''))
    });

    // Watch Files For Changes
    gulp.task('watch', function(){
      gulp.watch('scss/*.scss', ['sass']); 
      // Other watchers
    })

    // Run all Refinedby Tasks
    gulp.task('all', ['sass']);

You need to load the watcher when you call your "all task command".

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

or

gulp.task('all', ['sass'], function() { 
       gulp.start('watch');
});

or if you do not want to change your code just add

// Run all Refinedby Tasks
gulp.task('all', ['sass', 'watch']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM