-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
178 lines (141 loc) · 3.82 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Gulp.js configuration
const
// modules
gulp = require('gulp'),
imagemin = require('gulp-imagemin'),
htmlclean = require('gulp-htmlclean'),
postcss = require('gulp-postcss'),
assets = require('postcss-assets'),
autoprefixer = require('autoprefixer'),
cssnano = require('cssnano'),
purgecss = require('@fullhuman/postcss-purgecss'),
terser = require('gulp-terser'),
del = require("del"),
concat = require('gulp-concat'), // Added for MDBGulp
// Directories
dirSource = './src/assets/',
dirDistribution = './dist/assets/',
// CSS Processors settings
processors = [
autoprefixer({
overrideBrowserslist: ['last 10 versions'],
cascade: false
})
],
minifiers = [
cssnano(),
assets({
loadPaths: ['images/', 'fonts/'],
relative: true
})
],
// Image processing settings
imageSettings = [
imagemin.gifsicle({
interlaced: true
}),
imagemin.jpegtran({
progressive: true
}),
imagemin.optipng({
optimizationLevel: 5
}),
imagemin.svgo({
plugins: [{
removeViewBox: true
},
{
cleanupIDs: false
}
]
})
];
let out = '';
// ----------- HTML minifying ----------- //
// HTML Minifier
function html() {
const out = dirDistribution;
return gulp.src(dirSource + '**/*.html')
.pipe(htmlclean())
.pipe(gulp.dest(out));
}
exports.html = html;
// ----------- Image tampering ----------- //
// Image processing
function images() {
out = dirDistribution + 'images/';
return gulp
.src(dirSource + 'images/**/*')
.pipe(imagemin(imageSettings))
.pipe(gulp.dest(out));
}
exports.images = images;
// ----------- CSS ----------- //
// CSS compiling
function cssCompile() {
out = dirDistribution;
return gulp
.src(dirSource + '**/*.css')
.pipe(postcss(processors))
.pipe(gulp.dest(out));
}
exports.csscompile = cssCompile;
// CSS minifying
function cssMinify() {
out = dirDistribution;
return gulp
.src([dirDistribution + '**/*.css', '!' + dirDistribution + '**/*.min.css'])
.pipe(postcss(minifiers))
/* .pipe(rename({
suffix: '.min'
})) */
.pipe(gulp.dest(out));
}
exports.cssminify = cssMinify;
// ----------- JavaScript ----------- //
function jsCompile() {
out = dirDistribution;
return gulp
.src([dirSource + "**/*.js"])
// .pipe(eslint())
// .pipe(eslint.format())
// .pipe(eslint.failAfterError())
.pipe(gulp.dest(out));
}
exports.jscompile = jsCompile;
function jsMinify() {
out = dirDistribution;
return gulp
.src([dirDistribution + "**/*.js", "!" + dirDistribution + "**/*.min.js"])
.pipe(terser({
keep_fnames: true,
mangle: false
}))
/* .pipe(rename({
suffix: '.min'
})) */
.pipe(gulp.dest(out));
}
exports.jsminify = jsMinify;
// ----------- Utilities ----------- //
function moveManifest() {
let dirDistributionAlt = "./dist/";
return gulp
.src(["./src/*.json"])
.pipe(gulp.dest(dirDistributionAlt));
}
exports.moveManifest = moveManifest;
function moveFonts() {
out = dirDistribution + "fonts/";
return gulp
.src([dirSource + "fonts/*"])
.pipe(gulp.dest(out));
}
exports.moveFonts = moveFonts;
// Delete production directory
function clean() {
return del("./dist");
}
exports.clean = clean;
// ----------- Utilities for developing ----------- //
exports.build = gulp.series(clean, html, cssCompile, jsCompile, gulp.parallel(cssMinify, jsMinify, images, moveManifest, moveFonts));