my-portfolio/gulpfile.js

76 lines
1.7 KiB
JavaScript
Raw Normal View History

const gulp = require("gulp")
2021-06-29 22:23:24 +01:00
const browserSync = require("browser-sync").create();
const htmlMin = require("gulp-htmlmin");
const cssMin = require("gulp-clean-css")
const terser = require("gulp-terser");
2022-01-01 00:26:39 +00:00
const github = (process.env.github) ? true : false;
2021-06-29 22:23:24 +01:00
gulp.task("minifyHTML", () =>
{
return gulp.src("src/**/*.html" )
2021-06-29 22:23:24 +01:00
.pipe(htmlMin({collapseWhitespace: true}))
.pipe(gulp.dest("dist/"));
});
2021-06-29 22:23:24 +01:00
gulp.task("minifyCSS", () =>
{
return gulp.src("src/**/main.css")
2021-06-29 22:23:24 +01:00
.pipe(cssMin({compatibility: "ie8"}))
.pipe(gulp.dest("dist/"));
});
2021-06-29 22:23:24 +01:00
gulp.task("minifyJS", () =>
{
function createErrorHandler(name)
{
return function (err)
{
2021-06-29 22:23:24 +01:00
console.error("Error from " + name + " in compress task", err.toString());
};
}
return gulp.src("src/**/*.js")
.on("error", createErrorHandler("gulp.src"))
.pipe(terser())
.on("error", createErrorHandler("terser"))
.pipe(gulp.dest("dist/"))
.on("error", createErrorHandler("gulp.dest"));
});
2021-06-29 22:23:24 +01:00
2021-08-22 10:44:49 +01:00
gulp.task("movePHPFiles", () =>
{
return gulp.src("src/api/**/*.php")
.pipe(gulp.dest("dist/api/"))
2021-08-22 10:44:49 +01:00
});
gulp.task("watchFiles", () =>
{
gulp.watch("src/**/*.html", gulp.task("minifyHTML"));
gulp.watch("src/**/*.css", gulp.task("minifyCSS"));
gulp.watch("src/**/*.js", gulp.task("minifyJS"));
gulp.watch("src/api/**/*.php", gulp.task("movePHPFiles"))
});
2021-06-29 22:23:24 +01:00
gulp.task("browserSync", () =>
{
browserSync.init({
proxy: "https://rohitpai.co.uk/",
serveStatic: ["./dist"]
});
gulp.watch("dist").on("change", browserSync.reload)
2021-06-29 22:23:24 +01:00
});
2022-01-01 00:34:03 +00:00
gulp.task("default", async () =>
2022-01-01 00:26:39 +00:00
{
if(github)
{
(gulp.series("movePHPFiles", "minifyJS", "minifyHTML", "minifyCSS")());
}
else
{
(gulp.series(gulp.parallel("watchFiles", "browserSync"))());
2022-01-01 00:26:39 +00:00
}
2022-01-01 00:28:26 +00:00
});