-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·99 lines (86 loc) · 3.21 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
var gulp = require('gulp');
var cssnano = require('gulp-cssnano');
// var minifyCSS = require('gulp-minify-css');
var terser = require('gulp-terser');
const htmlmin = require('gulp-htmlmin');
var replace = require('gulp-replace');
var gzip = require('gulp-gzip');
var removeHtmlComments = require('gulp-remove-html-comments');
var clean = require('gulp-clean');
fs = require('fs');
gulp.task('css', function(done){
return gulp.src('esp32/DIY-Dyno/src/style.css')
.pipe(cssnano())
// .pipe(minifyCSS())
.pipe(gulp.dest('esp32/DIY-Dyno/build'))
done();
});
gulp.task('js', function(done){
return gulp.src('esp32/DIY-Dyno/src/javascript.js')
// .pipe(terser())
.pipe(gulp.dest('esp32/DIY-Dyno/build'))
done();
});
gulp.task('cssmax', function(done){
return gulp.src('esp32/DIY-Dyno/src/style.css')
// .pipe(cssnano())
// .pipe(minifyCSS())
.pipe(gulp.dest('esp32/DIY-Dyno/build'))
done();
});
gulp.task('jsmax', function(done){
return gulp.src('esp32/DIY-Dyno/src/javascript.js')
.pipe(gulp.dest('esp32/DIY-Dyno/build'))
done();
});
// gulp.task('html', function(done) {
// return gulp.src('esp32/DIY-Dyno/src/index.html')
// .pipe(htmlmin({ collapseWhitespace: true }))
// .pipe(gulp.dest('esp32/DIY-Dyno/build'))
// done();
// });
gulp.task('clean', function () {
return gulp.src('esp32/DIY-Dyno/build/*', {read: false})
.pipe(clean());
});
gulp.task('compress+gzip', function(done) {
gulp.src('esp32/DIY-Dyno/build/index.html')
.pipe(gzip())
.pipe(gulp.dest('esp32/DIY-Dyno/data'))
done();
});
gulp.task('compress', function(done) {
gulp.src('esp32/DIY-Dyno/build/index.html')
//.pipe(gzip())
.pipe(gulp.dest('esp32/DIY-Dyno/data'))
done();
});
gulp.task('html', function() {
return gulp.src('esp32/DIY-Dyno/src/index.html')
.pipe(removeHtmlComments())
.pipe(replace(/<link rel="stylesheet" type="text\/css" href="\/style.css"[^>]*>/, function(s) {
var style = fs.readFileSync('esp32/DIY-Dyno/build/style.css', 'utf8');
return '<style>\n' + style + '\n</style>';
}))
.pipe(replace(/<script src="\/javascript.js"\><\/script\>/, function(s) {
var script = fs.readFileSync('esp32/DIY-Dyno/build/javascript.js', 'utf8');
return '<script>\n' + script + '\n</script>';
}))
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('esp32/DIY-Dyno/build'));
});
gulp.task('htmlmax', function() {
return gulp.src('esp32/DIY-Dyno/src/index.html')
.pipe(replace(/<link rel="stylesheet" type="text\/css" href="\/style.css"[^>]*>/, function(s) {
var style = fs.readFileSync('esp32/DIY-Dyno/build/style.css', 'utf8');
return '<style>\n' + style + '\n</style>';
}))
.pipe(replace(/<script src="\/javascript.js"\><\/script\>/, function(s) {
var script = fs.readFileSync('esp32/DIY-Dyno/build/javascript.js', 'utf8');
return '<script>\n' + script + '\n</script>';
}))
.pipe(gulp.dest('esp32/DIY-Dyno/build'));
});
gulp.task('combine', gulp.series('cssmax', 'jsmax', 'htmlmax', 'compress', 'clean'));
gulp.task('combine+minify', gulp.series('css', 'js', 'html', 'compress', 'clean'));
gulp.task('combine+minify+gzip', gulp.series('css', 'js', 'html', 'compress+gzip', 'clean'));