-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
88 lines (76 loc) · 2.11 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (C) 2024 jmh
// SPDX-License-Identifier: GPL-3.0-only
"use strict";
import gulp from "gulp";
import environments from "gulp-environments";
import gulpSass from "gulp-sass"
import * as dartSass from "sass";
import cleanCSS from "gulp-clean-css"
import autoprefixer from "gulp-autoprefixer";
import babel from "gulp-babel";
import terser from "gulp-terser"
import {createGulpEsbuild} from "gulp-esbuild";
const esbuild = createGulpEsbuild({
incremental: false,
piping: true
});
const sass = gulpSass(dartSass);
const development = environments.development;
const production = environments.production;
const paths = {
js: {
src: "./js/**/*.js",
watch: "./js/**/*.js",
dest: "./stratum/static/dist/"
},
scss: {
entrypoints: ["./scss/main.scss"],
watch: ["./scss/*.scss", "./scss/**/*.scss"],
dest: "./stratum/static/dist/"
}
};
function scss() {
return gulp.src(paths.scss.entrypoints)
.pipe(sass.sync({
outputStyle: production() ? "compressed" : "expanded",
sourceMap: development()
})
.on("error", sass.logError))
.pipe(autoprefixer({
overrideBrowsersList: ["last 2 versions"],
cascade: false
}))
.pipe(cleanCSS({
level: {
1: {
all: production(),
specialComments: 0
}
}
}))
.pipe(gulp.dest(paths.scss.dest));
}
function js() {
return gulp.src(paths.js.src)
.pipe(babel({
presets: ["@babel/env"]
}))
.pipe(esbuild({
entryNames: "[dir]",
bundle: true,
treeShaking: production(),
legalComments: "none"
}))
.pipe(terser({
mangle: {
toplevel: true
}
}))
.pipe(gulp.dest(paths.js.dest));
}
function watch() {
gulp.watch(paths.scss.watch, scss);
gulp.watch(paths.js.watch, js);
}
gulp.task("default", gulp.series(gulp.parallel(scss, js), watch));
gulp.task("build", gulp.parallel(scss, js));