This repository has been archived on 2024-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
share2fedi/gulpfile.js
Nikita Karamov 9982dded07
Redo analytics again
This time I am manually calling the sendBeacon() function instead of
the script loading an image. This is faster, more privacy-friendly, and
more performant, since sendBeacon is being sent asynchronously. The
script I got at the end is also very small and hosted on my side.
2022-12-23 02:55:30 +01:00

47 lines
1.3 KiB
JavaScript

const { join, resolve } = require("path");
const gulp = require("gulp");
const postcss = require("gulp-postcss");
const sass = require("gulp-sass")(require("sass"));
const sourcemaps = require("gulp-sourcemaps");
const terser = require("gulp-terser");
const SOURCE_DIR = resolve(__dirname, "src");
const OUTPUT_DIR = resolve(__dirname, "public");
function html() {
return gulp.src(join(SOURCE_DIR, "index.html")).pipe(gulp.dest(OUTPUT_DIR));
}
function css() {
return gulp
.src(join(SOURCE_DIR, "scss", "*.scss"))
.pipe(sourcemaps.init())
.pipe(sass.sync().on("error", sass.logError))
.pipe(postcss([require("autoprefixer"), require("postcss-csso")]))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(OUTPUT_DIR));
}
function js() {
return gulp
.src([join(SOURCE_DIR, "main.js"), join(SOURCE_DIR, "count.js")])
.pipe(sourcemaps.init())
.pipe(terser({ ecma: 5 }))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(OUTPUT_DIR));
}
function static() {
return gulp
.src(join(SOURCE_DIR, "static", "**", "*"))
.pipe(gulp.dest(OUTPUT_DIR));
}
exports.default = gulp.parallel(html, css, js, static);
exports.watch = () => {
gulp.watch(join(SOURCE_DIR, "index.html"), html);
gulp.watch(join(SOURCE_DIR, "scss", "*.scss"), css);
gulp.watch(join(SOURCE_DIR, "*.js"), js);
gulp.watch(join(SOURCE_DIR, "static", "**", "*"), static);
};