forked from Ayush-Kanduri/Placement-Cell-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
113 lines (104 loc) · 3.25 KB
/
gulpfile.js
File metadata and controls
113 lines (104 loc) · 3.25 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//Require the Gulp Module for the Gulp Task Runner
const gulp = require("gulp");
//Require the Gulp-Sass Module for converting the SASS to CSS
const sass = require("gulp-sass")(require("node-sass"));
//Require the Gulp-CSSNano Module for Minifying the CSS
const cssnano = require("gulp-cssnano");
//Require the Gulp-Rev Module for Renaming the CSS Files
const rev = require("gulp-rev");
//Require the Uglify Module for Minifying the JS
const uglify = require("gulp-uglify-es").default;
//Require the ImageMin Module for Minifying the Images
const imagemin = require("gulp-imagemin");
//Require the Del Module for Deleting the Old Asset Files
const del = require("del");
//Minifies the CSS Files
gulp.task("css", (done) => {
console.log("Minifying CSS...");
//** means any folder and sub-folders inside
//**/!(*.min.css) means any file that does not have the .min.css extension
//* means any file
gulp
//Finds all the SASS files in the assets/scss folder
.src("./assets/sass/**/*.scss")
//The File will pass through the Gulp SASS Module and convert it to CSS
.pipe(sass())
//The File will pass through the Gulp CSSNano Module and minify it
.pipe(cssnano())
//Stores the file in the assets/css folder
.pipe(gulp.dest("./assets.css"));
//Pipe is a function which is calling all these Sub-Middlewares in Gulp
console.log("Minified CSS...");
//Finds the CSS files in the assets/css folder
gulp
.src("./assets/**/*.css")
//The File will pass through the Gulp Rev Module and rename it
.pipe(rev())
//Stores the file in the /public/assets/css folder
.pipe(gulp.dest("./public/assets"))
//Creates & Stores a Manifest File
.pipe(
rev.manifest({
//Current Working Directory is public as we are taking everything from the public folder
cwd: "public",
//If the name already exists, it will not change it, but will merge it with the original files
merge: true,
})
)
//Stores the Manifest File in the /public/assets folder
.pipe(gulp.dest("./public/assets"));
done();
});
//Minify the JS Files
gulp.task("js", (done) => {
console.log("Minifying JavaScript...");
gulp
.src("./assets/**/*.js")
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest("./public/assets"))
.pipe(
rev.manifest({
cwd: "public",
merge: true,
})
)
.pipe(gulp.dest("./public/assets"));
console.log("Minified JavaScript...");
done();
});
//Minifies the Images
gulp.task("images", (done) => {
console.log("Compressing Images...");
gulp
.src("./assets/**/*.+(png|jpg|gif|svg|jpeg)")
.pipe(imagemin())
.pipe(rev())
.pipe(gulp.dest("./public/assets"))
.pipe(
rev.manifest({
cwd: "public",
merge: true,
})
)
.pipe(gulp.dest("./public/assets"));
console.log("Compressed Images...");
done();
});
//Empty the public/assets Directory
gulp.task("clean:assets", (done) => {
//Whenever we are building the project, we need to clear the previous builds & build it from the scratch.
console.log("Clearing Previous Builds...");
del.sync(["./public/assets"], { force: true });
console.log("Cleared Previous Builds...");
done();
});
//Building the Assets by running the all the Gulp Tasks in the correct order
gulp.task(
"build",
gulp.series("clean:assets", "css", "js", "images"),
(done) => {
console.log("Building Assets...");
done();
}
);