const { notify } = require('browser-sync');
let project_folder = "dist";
let source_folder = "#src";
let path = {
build: {
html: project_folder + "/",
css: project_folder + "/css/",
js: project_folder + "/js/",
img: project_folder + "img/",
fonts: project_folder + "/fonts/",
},
src: {
html: [source_folder + "/*.html", "!" + source_folder + "/_*.html"],
css: source_folder + "/scss/style.scss",
js: source_folder + "/js/script.js",
img: source_folder + "img/**/*.{jpg,png,svg,gif,ico,webp}",
fonts: source_folder + "/fonts/*.ttf",
},
watch: {
html: source_folder + "/**/*.html",
css: source_folder + "/scss/**/*.scss",
js: source_folder + "/js/**/*.js",
img: source_folder + "img/**/*.{jpg,png,svg,gif,ico,webp}",
},
clean: "./" + project_folder + "/"
}
let { src, dest } = require('gulp'),
gulp = require('gulp'),
browsersync = require('browser-sync').create(),
fileinclude = require('gulp-file-include'),
del = require('del'),
postcss = require("gulp-postcss"),
scss = require("gulp-sass")(require("sass")),
autoprefixer = require("autoprefixer"),
group_media = require('gulp-group-css-media-queries'),
clean_css = require('gulp-clean-css'),
rename = require('gulp-rename');
function browserSync(params) {
browsersync.init({
server: {
baseDir: "./" + project_folder + "/"
},
port: 3000,
notify: false,
})
}
function html() {
return src(path.src.html)
.pipe(fileinclude())
.pipe(dest(path.build.html))
.pipe(browsersync.stream())
}
function css() {
return src(path.src.css)
.pipe(
scss({
outputStyle: "expanded",
}),
)
.pipe(
postcss([
autoprefixer({
overrideBrowserslist: ["last 5 versions"],
cascade: true,
}),
])
)
.pipe(
group_media()
)
.pipe(dest(path.build.css))
.pipe(clean_css())
.pipe(
rename({
extname: ".min.css"
})
)
.pipe(dest(path.build.css))
.pipe(browsersync.stream())
}
function images() {
return src(path.src.img)
.pipe(dest(path.build.img))
.pipe(browsersync.stream())
}
function fonts(params) {
src(path.src.fonts)
.pipe(ttf2woff())
.pipe(dest(path.build.fonts))
return src(path.src.fonts)
.pipe(ttf2woff2())
.pipe(dest(path.build.fonts))
}
function watchFiles(params) {
gulp.watch([path.watch.html], html);
gulp.watch([path.watch.css], css);
}
function clean(params) {
return del(path.clean);
}
let build = gulp.series(clean, gulp.parallel(images, css, html));
let watch = gulp.parallel(build, watchFiles, browserSync);
exports.fonts = fonts;
exports.html = html;
exports.css = css;
exports.build = build;
exports.watch = watch;
exports.default = watch;
function watchFiles(params) {
gulp.watch([path.watch.html], html);
gulp.watch([path.watch.css], css);
}
exports.fonts = fonts;
exports.html = html;
exports.css = css;
exports.build = build;
exports.watch = watch;
exports.default = watch;