const { series, parallel, src, dest } = require("gulp");
const browserSync = require('browser-sync').create();
const phpMinify = require('@cedx/gulp-php-minify');
const autoprefixer = require('gulp-autoprefixer');
const uglify = require('gulp-uglify');
const less = require('gulp-less');
const minifyCSS = require('gulp-csso');
const concat = require('gulp-concat');
const del = require('del');
const dir = {
"src": {
php: './app/*.php',
html: './',
css: './app/src/less/**/*.less',
js: './app/src/js/**/*.js',
},
"dest": {
build: './build/*',
php: './build/',
html: './',
css: './build/css/',
js: './build/js/',
}
}
function php() {
return src(dir.src.php, { read: false })
.pipe(phpMinify({ mode: 'fast' }))
.pipe(dest(dir.dest.php))
}
function css() {
return src(dir.src.css)
.pipe(less())
.pipe(autoprefixer())
.pipe(minifyCSS())
.pipe(dest(dir.dest.css))
.pipe(browserSync.stream())
}
function js() {
return src(dir.src.js, { sourcemaps: true })
.pipe(concat('app.min.js'))
.pipe(uglify())
.pipe(dest(dir.dest.js, { sourcemaps: true }))
.pipe(browserSync.stream())
}
function clean() {
return del(dir.dest.build)
}
function watch() {
browserSync.init({
server: {
baseDir: './app'
}
})
.pipe(watch(dir.src.css, css))
.pipe(watch(dir.src.js, js))
.pipe(watch(dir.src.php).on('change', browserSync.reload));
}
exports.js = js;
exports.css = css;
exports.php = php;
exports.clean = clean;
exports.watch = watch;
exports.build = series(this.clean, parallel(this.css, this.js))
exports.default = series(this.build, this.watch);