-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
80 lines (71 loc) · 1.53 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
/**
* Dependencies
**/
const gulp = require('gulp');
const csso = require('gulp-csso');
const rename = require('gulp-rename');
const htmlmin = require('gulp-htmlmin');
const minify = require('gulp-minify');
const nodemon = require('gulp-nodemon');
/**
* Tasks
**/
//minify CSS files
function minifyCSS() {
return gulp.src(['./src/css/*.css', '!./src/css/*.min.css'])
.pipe(csso())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./src/css/'))
}
//minify HTML files
function minifyHTML() {
return gulp.src(['./src/html/*.html', '!./src/html/*.min.html'])
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./src/html/'));
}
//minify JS files
function minifyJS() {
return gulp.src(['./src/js/*.js', '!./src/js/*.min.js'])
.pipe(minify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./src/js/'));
}
//watches files for changes
function watchAll(){
gulp.watch(['./src/css/*.css', '!./src/css/*.min.css'], gulp.series(minifyCSS));
gulp.watch(['./src/html/*.html', '!./src/html/*.min.html'], gulp.series(minifyHTML));
gulp.watch(['./src/js/*.js', '!./src/js/*.min.js'], gulp.series(minifyJS));
}
gulp.task('nodemon', function(cb) {
var called = false;
return nodemon({
script: 'index.js',
ignore: [
'gulpfile.js',
'node_modules/'
]
})
.on('start', function onStart() {
if (!called) { cb(); }
called = true;
})
});
/**
* Tasks export
**/
exports.default = gulp.series(
minifyCSS,
minifyHTML,
minifyJS,
gulp.parallel(
nodemon,
watchAll
)
)