-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·73 lines (64 loc) · 1.75 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
(function() {
'use strict';
var gulp = require('gulp');
var rename = require('gulp-rename');
var inline = require('gulp-inline-source');
var htmlmin = require('gulp-htmlmin');
var less = require('gulp-less');
var zlib = require('zlib');
var fs = require('fs');
var concat = require('gulp-concat');
var base64 = require('gulp-base64');
/**
*
*/
gulp.task('watch', ['gzip'], function() {
gulp.watch(__dirname + '/src/**/*.less', ['gzip']);
gulp.watch(__dirname + '/src/**/*.js', ['gzip']);
gulp.watch(__dirname + '/src/**/*.html', ['gzip']);
});
/**
*
*/
gulp.task('css', function(done){
return gulp.src(__dirname + '/src/**/*.less')
.pipe(less().on('error', handleError))
.pipe(gulp.dest(function(file){
return file.base;
}));
});
/**
*
*/
gulp.task('html', ['css'], function (done) {
return gulp.src('./src/index.html')
.pipe(inline({compress:true}))
.pipe(htmlmin({
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(rename('index_dev.html'))
.pipe(gulp.dest(__dirname));
});
gulp.task('gzip', ['html'], function(done){
var src = fs.readFileSync('./index_dev.html');
var template = fs.readFileSync('./src/index_compressed_template.html', 'utf8');
var data = zlib.gzipSync(src, {
level: 9,
windowBits: 15
});
data = data.toString('base64');
fs.writeFileSync('./index.html', template.replace('{$BUFFER}', data).replace('{$BUFFER_SIZE}', src.length));
return done();
});
gulp.task('build', ['gzip']);
/**
* @param err
*/
function handleError(err) {
var gutil = require('gulp-util');
gutil.log(gutil.colors.red(err));
this.emit('end');
}
}());