const
gulp = require('gulp'),
gulpsass = require('gulp-sass'),
browsersync = require("browser-sync"),
babel = require('gulp-babel'),
phpConnect = require('gulp-connect-php'),
concat = require('gulp-concat'),
concatCSS = require('gulp-concat-css'),
uglify = require('gulp-uglifyjs'),
cssnano = require('gulp-cssnano'),
rename = require('gulp-rename'),
del = require('del'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
cache = require('gulp-cache'),
autoprefixer = require('gulp-autoprefixer'),
htmlmin = require('gulp-htmlmin'),
function gulpSass() {
return gulp
.src('assets/sass/**/*.sass')
.pipe(gulpsass({ outputStyle: "expanded" }))
.pipe(autoprefixer(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], {cascade: true}))
.pipe(gulp.dest('assets/css'))
.pipe(browsersync.stream());
}
function libsJs() {
return gulp.src([
'assets/libs/jquery-3.3.1.min.js',
'assets/libs/bootstrap-4.3.1-dist/js/bootstrap.js',
'assets/libs/validator.min.js'
])
.pipe(concat('libs.min.js'))
.pipe(uglify({
toplevel: true
}))
.pipe(gulp.dest('assets/js'))
}
function scripts(){
return gulp
.src(['assets/js/main.js', 'assets/js/index.js'])
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(gulp.dest('assets/scripts'))
}
function libsCss() {
return gulp.src([
'assets/libs/bootstrap-4.3.1-dist/css/bootstrap.css',
'assets/css/animate.css'
])
.pipe(concatCSS('libs.css'))
.pipe(gulp.dest('assets/css'))
.pipe(cssnano())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('assets/css'))
}
function browserSync(done) {
phpConnect.server({
port: 8000,
notify: false,
keepalive: true,
base: "./"
}, function (){
browsersync({
proxy: '127.0.0.1:8000/'
});
});
done();
}
function clean() {
return del(["dist"]);
}
function cleanES() {
return del(["assets/script"]);
}
function clear() {
return cache.clearAll();
}
function images() {
return gulp
.src("assets/images/**/*")
.pipe((cache(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 5 }),
imagemin.svgo({
plugins: [
{
removeViewBox: false,
collapseGroups: true,
use: [pngquant()]
}
]
})
])))
)
.pipe(gulp.dest('dist/assets/images'));
}
function watchFiles(done) {
gulp.watch("./**/*.php", reload);
gulp.watch('assets/sass/**/*.sass', gulp.parallel(gulpSass));
gulp.watch('assets/js/**/*.js', reload);
gulp.watch('*.html', reload);
done();
}
function buildFiles(done) {
gulp.src([
'assets/css/main.css',
'assets/css/libs.min.css'
])
.pipe(cssnano())
.pipe(gulp.dest('dist/assets/css'));
gulp.src(
'assets/js/libs.min.js')
.pipe(gulp.dest('dist/assets/js'));
gulp.src(['assets/scripts/main.js'])
.pipe(uglify())
.pipe(gulp.dest('dist/assets/scripts'));
gulp.src(['assets/scripts/config-contact.js'])
.pipe(uglify({
toplevel: true
}))
.pipe(gulp.dest('dist/assets/scripts'));
gulp.src('static**!/!*')
.pipe(gulp.dest('dist'));
gulp.src('php**!/!*')
.pipe(gulp.dest('dist'));
gulp.src('*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'));
gulp.src('*.txt')
.pipe(gulp.dest('dist'));
gulp.src('*.xml')
.pipe(gulp.dest('dist'));
gulp.src('.htaccess')
.pipe(gulp.dest('dist'));
done();
}
const watch = gulp.series(watchFiles, gulp.parallel(cleanES, browserSync, scripts, libsJs, libsCss));
const build = gulp.series(clean, gulp.parallel(buildFiles, images, libsJs));
exports.clean = clean;
exports.clean = cleanES;
exports.clear = clear;
exports.watch = watch;
exports.build = build;
exports.default = watch;
function reload(done) {
browsersync.reload();
done();
}