-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.mjs
62 lines (53 loc) · 2.04 KB
/
gulpfile.mjs
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
/**
* Required packages
*/
import { deleteSync } from "del"; // Delete files and directories
import autoprefixer from "autoprefixer"; // Autoprefix CSS properties
import cleancss from "gulp-clean-css"; // Minify CSS
import dartSass from "sass"; // Compile SCSS to CSS
import duplicates from "postcss-discard-duplicates"; // Remove duplicate CSS rules
import gulp from "gulp"; // Gulp task runner
import gulpSass from "gulp-sass"; // Compile SCSS to CSS
import plumber from "gulp-plumber"; // Handle errors gracefully
import postcss from "gulp-postcss"; // Process CSS with PostCSS
import rename from "gulp-rename"; // Rename files
const sass = gulpSass(dartSass);
/**
* Build CSS from LESS files.
*
* @param {Function} done - A callback function to signal task completion.
*/
const buildCSS = (done) => {
gulp
.src("src/**/*.scss") // Source LESS files
.pipe(plumber()) // Handle errors gracefully
.pipe(sass()) // Compile SCSS to CSS
.pipe(postcss([duplicates(), autoprefixer()])) // Process CSS with PostCSS plugins
.pipe(cleancss({ format: "beautify" })) // Minify CSS
.pipe(rename({ suffix: ".user" })) // Rename output files
.pipe(gulp.dest("dist")); // Output directory
done(); // Signal task completion
};
/**
* Clean the build directory by deleting the 'dist' directory.
*
* @param {Function} done - A callback function to signal task completion.
*/
const cleanAssets = (done) => {
deleteSync("dist"); // Delete the 'dist' directory
done(); // Signal task completion
};
/**
* Watch for changes in LESS files and trigger the 'buildCSS' task.
*
* @param {Function} done - A callback function to signal task completion.
*/
const watchAssets = (done) => {
gulp.watch("src/**/*.scss", gulp.series(buildCSS)); // Watch LESS files for changes and run 'buildCSS' task
done(); // Signal task completion
};
// Define a series of tasks that should run in a sequence
const build = gulp.series(cleanAssets, buildCSS);
// Export the 'build' task and rename 'watchAssets' to 'watch' for better clarity.
export { build };
export { watchAssets as watch };