Gulp AssertionError - Sass Dependancies

时间:2018-06-08 15:54:32

标签: javascript gulp gulp-watch gulp-sass

尝试完成本教程以获得初学者的感受:

https://www.youtube.com/watch?v=nusgoj74a3Y

目前在运行gulp时遇到此错误,有什么想法吗?:

gulpfile.js

'use strict';


//dependancies
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');


// - SCSS/CSS

var SCSS_SRC = './src/Assets/scss/**/*.scss';
var SCSS_DEST = './src/Assets/css';


gulp.task('compile_scss', 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));

});

gulp.task('watch_scss', function() {
  gulp.watch(SCSS_SRC, ['compile_scss']);
});

gulp.task('default', ['watch_scss']);

输出

assert.js:269
    throw err;
    ^

AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (/Users/ss/Desktop/reactTest/my-app/node_modules/undertaker/lib/set-task.js:10:3)
at Gulp.task (/Users/ss/Desktop/reactTest/my-app/node_modules/undertaker/lib/task.js:13:8)
at Object.<anonymous> (/Users/ss/Desktop/reactTest/my-app/gulpfile.js:34:6)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)

有点难过,任何帮助都赞赏。

1 个答案:

答案 0 :(得分:2)

您正在使用gulp 4,术语已更改为

'use strict';


//dependancies
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');


// - SCSS/CSS

var SCSS_SRC = './src/Assets/scss/**/*.scss';
var SCSS_DEST = './src/Assets/css';


gulp.task('compile_scss', 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));

});

gulp.task('watch_scss', function() {
  gulp.watch(SCSS_SRC, gulp.series('compile_scss'));
});

gulp.task('default', ['watch_scss']);

基本上运行的文件更强大。你现在可以否定像runSequence这样的插件,因为它具有所有这些功能。

基本上你可以做的就是去

gulp.task('build', function (callback) {
    runSequence('runFirst', ['ranTogether1','ranTogether2'], 'ranLast'), callback
});

gulp.task('build',
  gulp.series('runFirst', gulp.parallel('ranTogether1', 'ranTogether2'),'ranLast'),
  function() {...}));

More info here