GULP看不到我的gulp.js文件

时间:2016-01-26 10:28:00

标签: javascript gulp gulp-watch gulp-sass

您好我试着在我的gulp.js文件中随时获取gulp手表。它需要运行我的sass并缩小它并设置到watch上的目标文件夹。有人可以帮忙吗?

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']);

1 个答案:

答案 0 :(得分:0)

您需要在调用“所有任务命令”时加载观察程序。

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

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

或者如果您不想更改代码,只需添加

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