-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
337 lines (278 loc) · 7.85 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
=========================================================
* Dash UI - Bootstrap 5 Admin & Dashboard Theme
=========================================================
* Product Page: https://codescandy.com/dashui/index.html
* Copyright 2020 Codescandy (https://codescandy.com/)
* Designed and coded by https://codescandy.com
========================================================= */
// Load plugins
const { src, dest, watch, parallel, series } = require("gulp");
const sass = require('gulp-sass')(require('sass'));
const gulpautoprefixer = require('gulp-autoprefixer');
const browsersync = require("browser-sync").create();
const fileinclude = require('gulp-file-include');
const useref = require('gulp-useref');
const cached = require("gulp-cached");
const gulpIf = require("gulp-if");
const del = require('del');
const npmDist = require('gulp-npm-dist');
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
const replace = require('gulp-replace');
const terser = require('gulp-terser');
var rename = require("gulp-rename");
var minify = require('gulp-minify');
const javascriptObfuscator = require('gulp-javascript-obfuscator');
// Paths to project folders
const paths = {
base:{
base: './',
node: './node_modules'
},
src:{
basesrc: './src',
basesrcfiles: './src/**/*',
scss: './src/assets/scss/**/*.scss',
css: './src/assets/css/*.css',
cssmap: './src/assets/css/*.css.map',
js: './src/assets/js/**/*.js',
jsmap: './src/assets/js/**/*.map',
jsmin: './src/assets/js/**/*.min.js',
vendor: './src/assets/vendor/**/*.*',
html: './src/**/*.html',
images: './src/assets/img/**/*',
audio: './src/assets/audio/**/*',
fonts: './src/assets/fonts/**/*',
partials: '.src/partials/**/*',
serverjs: './src/*.js',
certs: './src/certs/*',
layerslider:'./src/layerslider/**/*'
},
temp:{
basetemp: './.temp'
},
dist:{
basedist: './dist',
js: './dist/assets/js',
jsmin: './dist/assets/jsmin',
vendor: './dist/assets/vendor',
images: './dist/assets/img',
audio: './dist/assets/audio',
css: './dist/assets/css',
fonts: './dist/assets/fonts',
libs: './dist/assets/libs',
serverjs: './dist',
certs: './dist/certs',
assets: './dist/assets',
layerslider:'./dist/layerslider'
}
}
// layerslider
function layerslider(callback) {
return src(paths.src.layerslider)
.pipe(dest(paths.dist.layerslider));
callback();
}
// certs
function certs(callback) {
return src(paths.src.certs)
.pipe(dest(paths.dist.certs));
callback();
}
// serverjs node script
function serverjs(callback) {
return src(paths.src.serverjs)
.pipe(dest(paths.dist.serverjs));
callback();
}
// normal JS
function jsfilesDEV(callback) {
return src([paths.src.js,paths.src.jsmap,paths.src.jsmin])
.pipe(dest(paths.dist.js))
callback();
}
// *.js.map
function jsmap(callback) {
return src(paths.src.jsmap)
.pipe(dest(paths.dist.js))
callback();
}
// *.min.js
function jsmin(callback) {
return src(paths.src.jsmin)
.pipe(dest(paths.dist.js))
callback();
}
// normal JS
function jsfiles(callback) {
return src([paths.src.js, '!src/assets/js/**/*.min.js'])
// .pipe(minify())
.pipe(javascriptObfuscator())
// .pipe(dest(paths.dist.jsmin))
.pipe(dest(paths.dist.js))
callback();
}
// JS vendor
function vendor(callback) {
return src(paths.src.vendor)
.pipe(dest(paths.dist.vendor))
callback();
}
// Clean Dist folder
function cleanNonMinifyJS(callback) {
return src(paths.dist.jsmin+'/*-min.js')
.pipe(dest(paths.dist.js))
callback();
}
// CSS
function cssfiles(callback) {
return src([paths.src.css,paths.src.cssmap])
.pipe(dest(paths.dist.css))
callback();
}
// SCSS to CSS
function scss(callback) {
return src(paths.src.scss)
.pipe(sass().on("error", sass.logError))
.pipe(gulpautoprefixer())
.pipe(dest(paths.src.css))
.pipe(browsersync.stream());
callback();
}
// Image
function images(callback) {
return src(paths.src.images)
.pipe(dest(paths.dist.images))
callback();
}
// Audio
function audio(callback) {
return src(paths.src.audio)
.pipe(dest(paths.dist.audio))
callback();
}
// Font task
function fonts(callback) {
return src(paths.src.fonts)
.pipe(dest(paths.dist.fonts))
callback();
}
// HTML
function html(callback) {
return src([paths.src.html, '!./src/partials/**/*'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(replace(/src="(.{0,10})node_modules/g, 'src="$1assets/libs'))
.pipe(replace(/href="(.{0,10})node_modules/g, 'href="$1assets/libs'))
.pipe(useref())
.pipe(cached())
.pipe(gulpIf('*.css', postcss([ autoprefixer(), cssnano() ]))) // PostCSS plugins with cssnano
.pipe(gulpIf('*.js', terser()))
.pipe(gulpIf('*.html', rename(function(path){ path.extname = ".ejs";})))
.pipe(dest(paths.dist.basedist))
.pipe(browsersync.stream());
callback();
}
// File include task for temp
function fileincludeTask(callback) {
return src([paths.src.html, '!./src/partials/**/*'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file',
}))
.pipe(cached())
.pipe(dest(paths.temp.basetemp));
callback();
}
// Copy libs file from nodemodules to dist
function copyLibs(callback) {
return src(npmDist({
copyUnminified: true,
replaceDefaultExcludes: true,
excludes:[
'src/**/*',
'examples/**/*',
'example/**/*',
'demo/**/*',
'spec/**/*',
'docs/**/*',
'tests/**/*',
'test/**/*',
'Gruntfile.js',
'gulpfile.js',
'package.json',
'package-lock.json',
'bower.json',
'composer.json',
'yarn.lock',
'webpack.config.js',
'README',
'LICENSE',
'CHANGELOG',
'*.yml',
'*.md',
'*.coffee',
'*.ts',
'*.scss',
'*.less'
]
}),{base: paths.base.node})
.pipe(dest(paths.dist.libs));
callback();
}
// Clean .temp folder
function cleanTemp(callback) {
del.sync([paths.temp.basetemp, paths.dist.jsmin]);
callback();
}
// Clean Dist folder
function cleanDist(callback) {
del.sync(paths.dist.basedist);
callback();
}
// Browser Sync Serve
function browsersyncServe(callback){
browsersync.init({
server: {
baseDir: [paths.temp.basetemp, paths.src.basesrc, paths.base.base]
}
});
callback();
}
// SyncReload
function syncReload(callback){
browsersync.reload();
callback();
}
// Watch Task
function watchTaskWithBrowserSync(){
watch(paths.src.html, series( fileincludeTask, syncReload));
watch([paths.src.images, paths.src.fonts], series(images, fonts));
//watch([paths.src.scss], series(scss, syncReload));
}
// Watch Task
function watchTask(){
watch(paths.src.html, series(html));
watch(paths.src.js, series(jsfilesDEV));
watch(paths.src.serverjs, series(serverjs));
watch([paths.src.images, paths.src.fonts, paths.src.css], series(images, fonts, cssfiles));
//watch([paths.src.scss], series(scss));
}
// Default Task Preview
exports.default = series(parallel(cleanDist), certs, serverjs, jsfilesDEV, cssfiles, layerslider, vendor, html, images, audio, fonts, copyLibs, watchTask);
exports.preview = series( fileincludeTask, browsersyncServe, watchTaskWithBrowserSync);
// Build Task for Dist
exports.build = series(parallel(cleanDist), certs, serverjs, jsfiles, cssfiles, layerslider, jsmap, jsmin, vendor, cleanNonMinifyJS, html, images, audio, fonts, copyLibs, cleanTemp);
// export tasks
exports.scss = scss
exports.images = images;
exports.fonts = fonts
exports.html = html;
exports.fileincludeTask = fileincludeTask
exports.copyLibs = copyLibs
exports.cleanTemp = cleanTemp
exports.cleanDist = cleanDist