我是js的新手,并且正在学习教程。我安装了gulp并尝试编译sass文件时遇到错误。错误如下:
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (C:\Users\*****\Documents\GitHub\*****\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (C:\Users\*****\\Documents\GitHub\*****\\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (C:\Users\*****\\Documents\GitHub\*****\\gulpfile.js:38:6)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
我试图遵循gulp文档中的语法,但无法使其正常工作。
我的代码:
'use strict';
//dependencies
var gulp = require('gulp');
var sass = require('gulp-sass');
var minifyCSS = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var changed = require('gulp-changed');
var once = require('async-once');
///////////////
// - SCSS/CSS
///////////////
var SCSS_SRC = './src/assets/scss/**/*.scss';
var SCSS_DEST = './src/assets/css';
// Compile SCSS
gulp.task('styles', function () {
gulp.src(SCSS_SRC)
.pipe(sass().on('error', sass.logError))
.pipe(minifyCSS())
.pipe(rename({ suffix: '.min'}))
.pipe(changed(SCSS_DEST))
.pipe(gulp.dest(SCSS_DEST))
});
// detect changes in SCSS
gulp.task('watch_scss', function() {
gulp.watch(SCSS_SRC, ['compile_scss']);
});
// Run tasks
gulp.task('default', ['compile_scss']);
答案 0 :(得分:0)
看起来你没有从吞咽任务中得到回报。
试试: // 编译 SCSS
gulp.task('styles', function () {
**return** gulp.src(SCSS_SRC)
.pipe(sass().on('error', sass.logError))
.pipe(minifyCSS())
.pipe(rename({ suffix: '.min'}))
.pipe(changed(SCSS_DEST))
.pipe(gulp.dest(SCSS_DEST))
});