Раньше работало, а сейчас перестало.. уже все нервы съело..
let gulp = require('gulp');
const sass = require('gulp-sass')(require('node-sass'));
const autoprefixer = require('gulp-autoprefixer');
let browserSync = require('browser-sync')
let useref = require('gulp-useref');
let uglify = require('gulp-uglify-es').default;
let gulpIf = require('gulp-if');
let cssnano = require('gulp-cssnano');
let imagemin = require('gulp-imagemin');
let cache = require('gulp-cache');
let del = require('del');
let version = require('gulp-version-number');
// Development Tasks
// -----------------
// Start browserSync server
gulp.task('browserSync', function() {
browserSync({
server: {
baseDir: './app'
}
})
});
gulp.task('sass', function() {
return gulp.src('app/scss/**/*.scss') // Gets all files ending with .scss in app/scss and children dirs
.pipe(sass().on('error', sass.logError)) // Passes it through a gulp-sass, log errors to console
.pipe(autoprefixer())
.pipe(gulp.dest('app/css')) // Outputs it in the css folder
.pipe(browserSync.reload({ // Reloading with Browser Sync
stream: true
}));
});
// Watchers
gulp.task('watch', function() {
gulp.watch('app/scss/**/*.scss', gulp.series('sass'));
gulp.watch('app/*.html', browserSync.reload);
gulp.watch('app/js/**/*.js', browserSync.reload);
});
// Optimization Tasks
// ------------------
// Optimizing CSS and JavaScript
gulp.task('useref', function() {
return gulp.src('app/*.html')
.pipe(useref())
.pipe(gulpIf('*.js', uglify()))
.pipe(gulpIf('*.css', cssnano()))
.pipe(version({
'value': '%MDS%',
'append': {
'key': 'v',
'to': ['css', 'js'],
},
}))
.pipe(gulp.dest('dist'));
});
// Optimizing Images
gulp.task('images', function() {
return gulp.src('app/images/**/*.+(png|jpg|jpeg|gif|svg)')
// Caching images that ran through imagemin
.pipe(cache(imagemin({
interlaced: true,
})))
.pipe(gulp.dest('dist/images'))
});
// Copying fonts
gulp.task('fonts', function() {
return gulp.src('app/fonts/**/*')
.pipe(gulp.dest('dist/fonts'))
});
// Copying .htaccess
gulp.task('hta', function() {
return gulp.src('app/.htaccess')
.pipe(gulp.dest('dist/'))
});
// Cleaning
gulp.task('clean', function() {
return del.sync('dist').then(function(cb) {
return cache.clearAll(cb);
});
});
gulp.task('clean:dist', function() {
return del(['dist']);
});
// Build Sequences
// ---------------
// define complex tasks
const watch = gulp.parallel('sass', 'browserSync', gulp.series('watch'));
const build = gulp.series('clean:dist', 'sass', gulp.parallel('useref', 'images', 'fonts', 'hta'));
exports.watch = watch;
exports.build = build;