2021-09-13 09:15:50 +00:00
|
|
|
const { watch, series, src, dest } = require("gulp");
|
|
|
|
var browserSync = require("browser-sync").create();
|
2021-10-13 04:34:14 +00:00
|
|
|
const concat = require('gulp-concat');
|
2021-09-13 09:15:50 +00:00
|
|
|
var postcss = require("gulp-postcss");
|
|
|
|
const imagemin = require("gulp-imagemin");
|
2021-09-14 11:48:19 +00:00
|
|
|
const uglify = require('gulp-uglify-es').default;
|
2021-09-13 09:15:50 +00:00
|
|
|
|
|
|
|
function cssTask(cb) {
|
2021-10-13 04:34:14 +00:00
|
|
|
return src("./src/css/*.css")
|
2021-09-14 11:48:19 +00:00
|
|
|
.pipe(postcss())
|
2021-10-13 04:34:14 +00:00
|
|
|
.pipe(concat('style.min.css'))
|
|
|
|
.pipe(dest("./src/css"))
|
2021-09-14 11:48:19 +00:00
|
|
|
.pipe(browserSync.stream());
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
function scriptsTask(cb) {
|
2021-10-13 04:34:14 +00:00
|
|
|
return src('./src/js/*.js')
|
2021-09-14 11:48:19 +00:00
|
|
|
.pipe(uglify())
|
|
|
|
.pipe(dest('./dist/js'))
|
2021-09-13 09:15:50 +00:00
|
|
|
.pipe(browserSync.stream());
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Task for minifying images
|
|
|
|
function imageminTask(cb) {
|
2021-10-13 04:34:14 +00:00
|
|
|
return src("./src/assets/images/**/*")
|
2021-09-13 09:15:50 +00:00
|
|
|
.pipe(imagemin())
|
2021-09-17 10:06:02 +00:00
|
|
|
.pipe(dest("./dist/assets/images"));
|
2021-09-17 09:41:58 +00:00
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
function htmlBuild(cb) {
|
2021-10-13 04:34:14 +00:00
|
|
|
return src("./src/*.html")
|
2021-09-17 09:41:58 +00:00
|
|
|
.pipe(dest("./dist"))
|
2021-09-13 09:15:50 +00:00
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
function browsersyncServe(cb) {
|
|
|
|
browserSync.init({
|
|
|
|
server: {
|
2021-10-13 04:34:14 +00:00
|
|
|
baseDir: "src/",
|
2021-09-13 09:15:50 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
function browsersyncReload(cb) {
|
|
|
|
browserSync.reload();
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Watch Files & Reload browser after tasks
|
|
|
|
function watchTask() {
|
2021-10-13 04:34:14 +00:00
|
|
|
watch("./src/**/*.html", browsersyncReload);
|
|
|
|
watch(["./src/css/*.css"], series(cssTask, browsersyncReload));
|
|
|
|
watch(["./src/js/*.js"], series(scriptsTask, browsersyncReload));
|
2021-09-13 09:15:50 +00:00
|
|
|
}
|
|
|
|
|
2021-10-13 04:34:14 +00:00
|
|
|
function build() {
|
|
|
|
return src([
|
|
|
|
'src/css/style.min.css',
|
|
|
|
'src/assets/images/**/*',
|
|
|
|
'src/js/main.js',
|
|
|
|
'src/**/*.html ',
|
|
|
|
], {base: 'src'})
|
|
|
|
.pipe(dest('dist'))
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.build = series(build);
|
2021-09-17 09:41:58 +00:00
|
|
|
exports.default = series(cssTask, scriptsTask, htmlBuild, browsersyncServe, watchTask);
|
2021-09-13 09:15:50 +00:00
|
|
|
exports.css = cssTask;
|
|
|
|
exports.images = imageminTask;
|