S
S
shadowcat2018-07-31 00:09:55
gulp.js
shadowcat, 2018-07-31 00:09:55

Error while compiling Gulp (new version error)?

help with galp error

assert.js:269
throw err;
^
AssertionError [ERR_ASSERTION]: Task function must be specified

gulp local version 4.0.0
gulp CLI version 2.0.1
node version 10.5.0
var gulp = require('gulp'),
  sass = require('gulp-sass'),
  browserSync = require('browser-sync'),
  concat = require('gulp-concat'),
  uglify = require('gulp-uglifyjs'),
  cssnano = require('gulp-cssnano'),
  rename = require('gulp-rename'),
  del = require('del'),
  imagemin = require('gulp-imagemin'),
  pngquant = require('imagemin-pngquant'),
  cache = require('gulp-cache'),
  autoprefixer = require('gulp-autoprefixer');

gulp.task('sass', function(){
  return gulp.src('app/sass/*.sass')
  .pipe(sass())
  .pipe(autoprefixer(['last 7 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true}))
  .pipe(gulp.dest('app/css'))
  .pipe(browserSync.reload({stream: true}))
});


gulp.task('scripts', function(){
  return gulp.src([
    'app/libs/bootstrap-3.3.7-dist/js/bootstrap.min.js'
  ])
  .pipe(concat('libs.min.js'))
  .pipe(uglify())
  .pipe(gulp.dest('app/js'));
});

gulp.task('css-libs', ['sass'], function(){
  return gulp.src('app/css/libs.css')
  .pipe(cssnano())
  .pipe(rename({suffix: '.min'}))
  .pipe(gulp.dest('app/css'));
});

gulp.task('browser-sync', ['sass', 'scripts'], function() {
    browserSync.init({
        proxy: "project",
        notify: false
    });
});

gulp.task('clean', function(){
  return del.sync([
    'www/web/css',
    'www/web/img',
    'www/web/js'
  ]);
});

gulp.task('clear', function(){
  return cache.clearAll();
});

gulp.task('img', function(){
  return gulp.src('app/img/**/*')
  .pipe(cache(imagemin({
    interlaced: true,
    progressive: true,
    svgoPlugins: [{removeViewBox: false}],
    use: [pngquant()]
  })))
  .pipe(gulp.dest('www/web/img'));
});

gulp.task('watch', ['browser-sync', 'scripts'], function(){
  gulp.watch('app/sass/*.sass', ['sass']);
  gulp.watch('app/*.html', browserSync.reload);
  gulp.watch('www/views/*.php', browserSync.reload);
  gulp.watch('app/js/*.js', browserSync.reload);
});

gulp.task('build',['clean', 'img', 'sass', 'scripts'], function(){
  var buildCss = gulp.src([
    'app/css/main.css',
    'app/css/libs.min.css',
  ])
    .pipe(gulp.dest('www/web/css'));

  var buildFonts = gulp.src('app/fonts/**/*')
    .pipe(gulp.dest('www/web/fonts'));

  var buildJs = gulp.src('app/js/**/*')
    .pipe(gulp.dest('www/web/js'));

  var buildHtml = gulp.src('app/*.html')
    .pipe(gulp.dest('www/views/html'));

});

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Klimov, 2018-12-16
@klimjr

in gulp4, functions must have names.
You need to call something like this:

function sassFunc() {
    return gulp.src('app/sass/*.sass')
  .pipe(sass())
  .pipe(autoprefixer(['last 7 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true}))
  .pipe(gulp.dest('app/css'))
  .pipe(browserSync.reload({stream: true}))

}

gulp.task('sass', sassFunc);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question