-
Notifications
You must be signed in to change notification settings - Fork 362
/
gulpfile.js
70 lines (63 loc) · 2.1 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
const gulp = require("gulp");
const less = require("gulp-less");
const path = require("path");
const clean = require("gulp-clean");
const cssmin = require("gulp-cssnano");
const plumber = require("gulp-plumber");
const rename = require("gulp-rename");
const sourcemaps = require("gulp-sourcemaps"); // Import sourcemaps
// Define paths
// Define paths
const paths = {
less: "app/less/metro-bootstrap.less", // Main LESS file
dist: "dist/css/", // Destination folder for compiled CSS
fonts: "app/fonts/**/*", // Path to the original font files
fontsDist: "dist/fonts/", // Destination for moved font files
};
// Task to compile LESS files
gulp.task("less", function () {
return (
gulp
.src(paths.less)
.pipe(
plumber({
errorHandler: function (err) {
console.error("Error!", err.message);
this.emit("end");
},
}),
)
.pipe(sourcemaps.init()) // Initialize sourcemaps
.pipe(
less({
paths: [path.join(__dirname, "app/less")],
}),
)
.pipe(rename("metro-bootstrap.css")) // Rename to metro-bootstrap.css
.pipe(gulp.dest(paths.dist)) // Output the non-minified CSS
.pipe(cssmin()) // Minify CSS
.pipe(rename("metro-bootstrap.min.css")) // Rename to metro-bootstrap.min.css
.pipe(gulp.dest(paths.dist)) // Output the minified CSS
// Write sourcemaps after minification
.pipe(
sourcemaps.write(".", {
mapFile: function () {
return "metro-bootstrap.css.map"; // Rename the sourcemap file
},
}),
)
.pipe(gulp.dest(paths.dist))
); // Output the source map
});
// Task to copy font files
gulp.task("fonts", function () {
return gulp
.src(paths.fonts) // Source font files
.pipe(gulp.dest(paths.fontsDist)); // Destination for font files
});
// Task to clean the dist folder
gulp.task("clean", function () {
return gulp.src("dist", { read: false, allowEmpty: true }).pipe(clean());
});
// Default task to clean, compile LESS, and copy fonts
gulp.task("default", gulp.series("clean", "less", "fonts"));