-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
71 lines (64 loc) · 1.93 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
// Initialize modules
// Importing specific gulp API functions lets us write them below as series() instead of gulp.series()
const { src, dest, watch, series, parallel } = require('gulp');
// Importing all the Gulp-related packages we want to use
const concat = require('gulp-concat');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const sass = require('gulp-sass');
let cleanCSS = require('gulp-clean-css');
var replace = require('gulp-replace');
// File paths
const files = {
scssPath: './sass/*.scss',
jsPath: './js/*.js'
}
// minifies css
function scssTask(){
return src(files.scssPath)
.pipe(sass().on('error',sass.logError))
.pipe(cleanCSS())
.pipe(concat('style.min.css'))
.pipe(dest('dist/css')
); // put final CSS in dist folder
}
// JS task: concatenates and uglifies JS files to script.min.js
function jsTask(){
return src([
files.jsPath
//,'!' + 'includes/js/jquery.min.js', // to exclude any specific files
])
.pipe(concat('script.min.js'))
.pipe(babel({
presets:["@babel/preset-env"]
}))
.pipe(uglify())
.pipe(dest('dist/js')
);
}
// Cachebust
function cacheBustTask(){
var cbString = new Date().getTime();
return src(['index.html'])
.pipe(replace(/cb=\d+/g, 'cb=' + cbString))
.pipe(dest('.'));
}
// Watch task: watch css and JS files for changes
// If any change, run scss and js tasks simultaneously
function watchTask(){
watch([files.scssPath, files.jsPath],
{interval: 1000, usePolling: true}, //Makes docker work
series(
parallel(scssTask, jsTask),
cacheBustTask
)
);
}
// Export the default Gulp task so it can be run
// Runs the css and js tasks simultaneously
// then runs cacheBust, then watch task
exports.default = series(
parallel(scssTask, jsTask),
cacheBustTask,
watchTask
);