var gulp = require('gulp'),
concat = require('gulp-concat'),
autoprefixer = require('gulp-autoprefixer'),
cleanCSS = require('gulp-clean-css'),
uglify = require('gulp-uglify'),
del = require('del'),
browserSync = require('browser-sync').create(),
sass = require('gulp-sass');
const jsFiles = [
'app/js/lib.js',
'app/js/main.js'
]
gulp.task('sass', function() {
return gulp.src('app/sass/**/*.sass')
.pipe(sass())
.pipe(gulp.dest('app/css'))
.pipe(autoprefixer({ cascade: false }))
.pipe(cleanCSS({ level: 2 }))
.pipe(gulp.dest('dist/css'))
.pipe(browserSync.stream())
})
function scripts() {
return gulp.src(jsFiles)
.pipe(concat('script.js'))
.pipe(uglify({
toplevel: true
}))
.pipe(gulp.dest('dist/js'))
.pipe(browserSync.stream())
}
function clean() {
return del(['build/*'])
}
function watch() {
browserSync.init({
server: {
baseDir: "./"
}
});
gulp.watch('app/sass/**/*.sass', sass);
gulp.watch('app/js/**/*.js', scripts);
gulp.watch('*.html').on('change', browserSync.reload);
}
gulp.task('sass', sass);
gulp.task('scripts', scripts);
gulp.task('del', clean);
gulp.task('watch', watch);
gulp.task('build', gulp.series(clean, gulp.parallel(sass, scripts)));
gulp.task('dev', gulp.series('build', 'watch'));