任务' sass'不在你的Gulpfile中 - 错误

时间:2017-05-13 07:49:24

标签: javascript sass gulp gulp-sass gulp-browser-sync

以下是我遇到此错误的代码请帮我解决这个问题,我会很高兴得到明确答案___

一切都运行顺畅,但除非我保存文件,否则会发生以下错误

错误:任务' sass'不在你的gulpfile中

    // require gulp
var gulp = require('gulp');

// require other packages
var concat = require('gulp-concat'),
cssmin = require('gulp-minify-css'),
rename = require("gulp-rename"),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
autoprefix = require('gulp-autoprefixer');
changed = require('gulp-changed'),


// scripts task
gulp.task('scripts', function() {
  return gulp.src('./src/js/*.js')
  .pipe(concat('app.js'))
  .pipe(gulp.dest('./dist/js/'))
  .pipe(uglify())
  .pipe(rename({
    suffix: '.min'
  }))
  .pipe(gulp.dest('./dist/js/'));
});

// styles task and autoprefix
gulp.task('styles', function() {
  gulp.src(['./src/sass/*.scss'])
  .pipe(autoprefix('last 2 versions'))
  .pipe(sass())
  .pipe(concat('styles.css'))
  .pipe(cssmin())
  .pipe(rename({
    suffix: '.min'
  }))
  .pipe(gulp.dest('./dist/css/'));
});


// browser sync
gulp.task('browser-sync', ['styles'], function() {
  browserSync({
    server: {
      baseDir: ''
    },
    notify: false
  });
  gulp.watch("./src/sass/*.scss", ['scss']);
  gulp.watch("*.html").on('change', browserSync.reload);
});

// watch task
gulp.task('watch', function() {
  gulp.watch('./src/js/*.js', ['scripts']);
  gulp.watch('./src/sass/*.scss', ['styles']);
});

// image minification
gulp.task('imagemin', function() {
  var imgSrc = './src/img/**/*',
  imgDst = './dist/img';

  gulp.src(imgSrc)
  .pipe(changed(imgDst))
  .pipe(imagemin())
  .pipe(gulp.dest(imgDst));
});

gulp.task('default', ['scripts', 'styles', 'browser-sync', 'imagemin', 'watch']);

1 个答案:

答案 0 :(得分:1)

你确实没有定义" sass"任务也不是" scss"在"浏览器同步"下标记为可靠的任务文件。

尝试更换:

gulp.watch("./src/sass/*.scss", ['scss']);

gulp.watch("./src/sass/*.scss", ['styles']);