I just started learning gulp and i followed this tutorial series: https://www.youtube.com/watch?v=ax0ykSVPufs&list=PLriKzYyLb28lp0z-OMB5EYh0OHaKe91RV&index=7
I got this all working until i updated my node and npm versions,i encountered an error. Here's my gulpfile.js
const gulp = require('gulp');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const autoprefixer = require('gulp-autoprefixer');
const sourcemaps = require('gulp-sourcemaps');
const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
let styleSource = 'src/scss/style.scss';
let styleDestination = './build/css/';
let styleWatch = 'src/scss/**/*.scss';
let jsSource = 'main.js';
let jsFolder = 'src/js/';
let jsDestination = './build/js/';
let jsWatch = 'src/js/**/*.js';
let jsFILES = [jsSource];
let htmlWatch = '**/*.html';
/* Converting Sass to CSS */
gulp.task('styles',function(){
gulp.src(styleSource)
.pipe(sourcemaps.init())
.pipe(sass({
errorLogToConsole: true,
outputStyle: 'compressed'
}))
.on('error', console.error.bind(console))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(rename({suffix:'.min'}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(styleDestination));
});
/* Converting ES6 to Vanilla JS */
gulp.task('js',function(){
jsFILES.map(function(entry){
return browserify({
entries: [`${jsFolder}${entry}`]
})
.transform(babelify, {presets:['env']})
.bundle()
.pipe(source(entry))
.pipe( rename({extname:'.min.js'}) )
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(jsDestination))
});
})
// default task to run all tasks
gulp.task('default', ['styles','js']);
// watch default
gulp.task('watch', ['default'], function(){
gulp.watch(styleWatch, ['styles']);
gulp.watch(jsWatch, ['js']);
gulp.watch(htmlWatch);
});
After i entered the gulp command in the terminal i got this error:
assert.js:42
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (D:\Web Design and Development\Tutorials\Web Design and Development\My Javascript Skills Projects\javascript30\javascript30-day-two\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (D:\Web Design and Development\Tutorials\Web Design and Development\My Javascript Skills Projects\javascript30\javascript30-day-two\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (D:\Web Design and Development\Tutorials\Web Design and Development\My Javascript Skills Projects\javascript30\javascript30-day-two\gulpfile.js:63:6)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
Welcome to Gulp. Gulp 4!
Probably your tutorial is for Gulp 3
will not work in Gulp 4 due to a new task execution system
Instead you have to do something like
Same with
gulp.task('watch', ['default'], function(){...
More in details:
https://www.liquidlight.co.uk/blog/how-do-i-update-to-gulp-4/
https://fettblog.eu/gulp-4-parallel-and-series/