wakuconnect.dev/gulpfile.js

74 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-09-13 09:15:50 +00:00
const { watch, series, src, dest } = require("gulp");
var browserSync = require("browser-sync").create();
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) {
return src("./src/css/*.css")
2021-09-14 11:48:19 +00:00
.pipe(postcss())
.pipe(concat('style.min.css'))
.pipe(dest("./src/css"))
2021-09-14 11:48:19 +00:00
.pipe(browserSync.stream());
cb();
}
function scriptsTask(cb) {
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) {
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) {
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: {
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() {
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
}
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;