I am trying to debug an error in my GULP file. I cannot seem to work out what exactly I should change. The error is as following:
Replace Autoprefixer browsers option to Browserslist config. Use browserslist key in package.json or .browserslistrc file.
Using browsers option cause some error. Browserslist config can be used for Babel, Autoprefixer, postcss-normalize and other tools.
If you really need to use option, rename it to overrideBrowserslist.
Learn more at: https://github.com/browserslist/browserslist#readme https://twitter.com/browserslist
[12:20:01] The following tasks did not complete: default, compile-scss [12:20:01] Did you forget to signal async completion?
var gulp = require('gulp');
// Include plugins
var path = require('path');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var cleanCSS = require('gulp-clean-css');
var folders = require('gulp-folders');
var imagemin = require('gulp-imagemin');
// Config
var inputFolders = 'src'
var outputFolders = 'public'
var scssInput = 'styles';
var scssOutput = 'styles'
var jsInput = 'scripts';
var jsOutput = 'scripts';
var mediaInput = 'images';
var mediaOutput = 'images';
var backupImageFolder = 'backup-image';
// compile scss into css
gulp.task('compile-scss', folders(inputFolders, function (folder) {
var processors = [
autoprefixer({browsers: ['last 2 versions', 'IE 10', 'Safari 8']})
];
return gulp.src(inputFolders + '/' + folder + '/' + scssInput + '/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss(processors))
.pipe(cleanCSS({compatibility:'*'}))
.pipe(gulp.dest(outputFolders + '/' + folder + '/' + scssOutput));
}));
// concatenate and minify js
gulp.task('scripts', folders(inputFolders, function(folder) {
return gulp.src(inputFolders + '/' + folder + '/' + jsInput + '/*.js')
// .pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(gulp.dest(outputFolders + '/' + folder + '/' + jsOutput));
}));
// deploy any media and losslessly optimise if possible
gulp.task('media', folders(inputFolders, function(folder) {
return gulp.src([inputFolders + '/' + folder + '/' + mediaInput + '/*', inputFolders + '/' + folder + '/' + mediaInput + '/**/*'])
.pipe(imagemin())
.pipe(gulp.dest(outputFolders + '/' + folder + '/' + mediaOutput));
}));
// copy across html
gulp.task('html', folders(inputFolders, function(folder) {
return gulp.src(inputFolders + '/' + folder + '/*.html')
.pipe(gulp.dest(outputFolders + '/' + folder))
}));
// copy across back-up image for the banner
gulp.task('copy-backup-image', folders(inputFolders, function(folder) {
return gulp.src(inputFolders + '/' + folder + '/' + backupImageFolder + '/*' )
.pipe(gulp.dest(outputFolders + '/' + folder + '/' + backupImageFolder))
}));
// Watch files for changes, run affected tasks
gulp.task('watch', function() {
gulp.watch([inputFolders + '/*/' + scssInput + '/*.scss'], gulp.series('compile-scss'));
gulp.watch([inputFolders + '/*/' + scssInput + '/**/*.scss'], gulp.series('compile-scss'));
gulp.watch([inputFolders + '/*/' + jsInput + '/*.js'], gulp.series('scripts'));
gulp.watch([inputFolders + '/*/' + mediaInput + '/*'], gulp.series('media'));
gulp.watch([inputFolders + '/*/' + mediaInput + '/**/*'], gulp.series('media'));
gulp.watch([inputFolders + '/*/*.html'], gulp.series('html'));
gulp.watch([inputFolders + '/*/' + backupImageFolder + '/*'], gulp.series('copy-backup-image'));
});
// Default task
gulp.task('default',
gulp.series(gulp.parallel('compile-scss', 'scripts', 'media', 'html', 'copy-backup-image'), 'watch'));
Make a .browserslistrc
in your working root or workspace directory with something like this in it:
# Browsers that we support
last 2 versions
IE 10
Safari 8
And then change this code:
var processors = [
autoprefixer({browsers: ['last 2 versions', 'IE 10', 'Safari 8']})
];
to simply:
var processors = [
autoprefixer()
];
That should get rid of the complaint about the browsers
option. Then run your default
task to see if that fixed your 'compile-scss'
failed to complete error message and report back.
Now for the async signal problem. That gulp-folders
plugin has not been updated for 5 years so I suggest a different approach.
const glob = require('glob');
// this gets an array of matching folders
const folders = glob.sync(inputFolders');
gulp.task('compile-scss', () => {
let stream;
// work on each folder separately
folders.forEach(function (folder) {
stream = gulp.src( inputFolders + '/' + folder + '/' + scssInput + '/*.scss' )
// do your other stuff
.pipe(gulp.dest( outputFolders + '/' + folder + '/' + scssOutput ));
});
return stream;
});