Answer the question
In order to leave comments, you need to log in
Error while running gulp. How to fix?
Hello, can you tell me what is wrong?
Here is the gulp file code:
let preprocessor = 'sass';
const {app, dest, parallel, watch} = require('gulp'),
browserSync = require('browser-sync').create(),
concat = require('gulp-concat'),
uglify = require('gulp-uglify-es').default(),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
cleancss = require('gulp-clean-css'),
imagemin = require('gulp-imagemin'),
newer = require('gulp-newer'),
del = require('del');
function browsersync() {
browserSync.init({
server: {'baseDir': 'src/'},
notify: false,
online: true
});
}
function scripts() {
return app([
'src/js/script.js'
])
.pipe(concat('script.min.js'))
.pipe(uglify())
.pipe(dest('src/js/'))
.pipe(browserSync.stream());
}
function startwatch() {
watch(['src/**/*.js', '!src/**/*.min.js'], scripts);
watch('src/**/' + preprocessor + '/**/*', styles);
watch('src/**/*.html').on('change', browserSync.reload);
watch('src/images/**/*', images);
}
function styles() {
return app('src/' + preprocessor + '/style.' + preprocessor + '')
.pipe(eval(preprocessor)())
.pipe(concat('style.min.css'))
.pipe(autoprefixer({ overrideBrowserslist: ['last 10 versions'], grid: true }))
.pipe(cleancss( { level: { 1: { specialComments: 0 } }} ))
.pipe(dest('src/css/'))
.pipe(browserSync.stream());
}
function images() {
return app('src/images/**/*')
.pipe(newer('src/images'))
.pipe(imagemin())
.pipe(dest('src/images'));
}
function cleanimg() {
return del('src/images/**/*', { force: true });
}
exports.browsersync = browsersync;
exports.scripts = scripts;
exports.styles = styles;
exports.images = images;
exports.cleanimg = cleanimg;
exports.default = parallel(styles, scripts, browsersync, startwatch);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question