generated from harvanchik/tailwind-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.mjs
137 lines (127 loc) · 3.33 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import gulp from 'gulp';
import { readFileSync } from 'fs';
import { deleteAsync } from 'del';
import htmlmin from 'gulp-htmlmin';
import jsmin from 'gulp-minify';
import svgmin from 'gulp-svgmin';
import image from 'gulp-image';
import rev from 'gulp-rev';
import rewrite from 'gulp-rev-rewrite';
const root = './'; // the path to the root of your project (you probably do not need to change this)
const destination = `${root}docs`; // the destination folder of the gulped content (change as needed (i.e. 'docs'))
const manifest = `${root}rev-manifest.json`; // the name of the manifest file (do not edit unless you know what you're doing)
/**
* Minify the HTML
*/
function html() {
return gulp
.src([`${root}**/*.html`, `!${root}node_modules/**/*.html`, `!${destination}/**/*.html`])
.pipe(
htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: true,
removeEmptyAttributes: true,
removeAttributeQuotes: true,
})
)
.pipe(rewrite({ manifest: readFileSync(manifest) }))
.pipe(gulp.dest(destination));
}
/**
* Copy the Styles
*/
function styles() {
return gulp
.src([`${root}assets/styles/styles.css`])
.pipe(rev())
.pipe(gulp.dest(`${destination}/assets/styles`))
.pipe(rev.manifest(manifest, { merge: false }))
.pipe(gulp.dest(root));
}
/*
* Minify the JavaScript
*/
function javascript() {
return gulp
.src([`${root}assets/js/*.js`])
.pipe(
jsmin({
noSource: true,
ext: { min: '.js' },
compress: {
dead_code: true,
unused: true,
drop_debugger: true,
},
output: {
comments: false,
quote_style: 1,
},
})
)
.pipe(rev())
.pipe(gulp.dest(`${destination}/assets/js`))
.pipe(rev.manifest(manifest, { merge: true }))
.pipe(gulp.dest(root));
}
/**
* Copy & Optimize the Images
*/
function images() {
return gulp
.src([`${root}assets/img/**/*.{png,jpg,jpeg,jfif,gif,webp,pdf,ico,bmp,tif,tiff,raw,cr2,nef,sr2,heif,hdr,ppm,pgm,pbm,pnm,exif}`])
.pipe(
image({
quiet: true, // set to false to log results for every image processed
})
)
.pipe(rev())
.pipe(gulp.dest(`${destination}/assets/img`))
.pipe(rev.manifest(manifest, { merge: true }))
.pipe(gulp.dest(root));
}
/**
* Copy the favicon.ico
*/
function favicon() {
return gulp
.src([`${root}favicon.ico`])
.pipe(rev())
.pipe(gulp.dest(`${destination}`))
.pipe(rev.manifest(manifest, { merge: true }))
.pipe(gulp.dest(root));
}
/**
* Minify the SVGs
*/
function svg() {
return gulp
.src([`${root}assets/img/svg/*.svg`])
.pipe(svgmin())
.pipe(rev())
.pipe(gulp.dest(`${destination}/assets/img/svg`))
.pipe(rev.manifest(manifest, { merge: true }))
.pipe(gulp.dest(root));
}
/**
* Copy CNAME
*/
function cname() {
return gulp.src([`${root}CNAME`]).pipe(gulp.dest(destination));
}
/**
* Remove all content within the destination folder
*/
function clean() {
return deleteAsync([`${destination}`]);
}
/**
* The default task (triggered when running 'gulp' in the console)
*/
gulp.task('default', gulp.series(clean, styles, javascript, images, svg, favicon, html, cname));
/**
* Task to remove the destination folder and its contents.
*/
gulp.task('clean', clean);