generated from harvanchik/tailwind-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.mjs
124 lines (116 loc) · 2.98 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
import gulp from 'gulp';
import { readFileSync } from 'fs';
import del 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,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));
}
/**
* 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));
}
/**
* Remove all content within the destination folder
*/
function clean() {
return del([`${destination}`]);
}
/**
* The default task (triggered when running 'gulp' in the console)
*/
gulp.task('default', gulp.series(clean, styles, javascript, images, svg, html));
/**
* Task to remove the destination folder and its contents.
*/
gulp.task('clean', clean);