-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
74 lines (68 loc) · 1.67 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
var gulp = require('gulp');
var minifyCss = require('gulp-minify-css');
var htmlmin = require('gulp-html-minifier');
var filter = require('gulp-filter');
var uglify = require('gulp-uglify');
var rev = require('gulp-rev');
var revReplace = require('gulp-rev-replace');
var useref = require('gulp-useref');
var del = require('del');
var runSequence = require('run-sequence');
var dest = './dist';
gulp.task('clean', function () {
return del([dest]);
});
gulp.task('copy', function () {
return gulp.src([
'assets/img/**/*',
'assets/js/uglify.min.js',
'assets/js/worker.js',
'assets/json/modules.json'
], {base: '.'})
.pipe(gulp.dest(dest));
});
gulp.task('build', function () {
var jsFilter = filter('**/*.js');
var cssFilter = filter('**/*.css');
var assets = useref.assets();
return gulp.src('./index.html')
.pipe(assets)
.pipe(jsFilter)
.pipe(uglify({
output: {
beautify: false
},
compress: {
sequences: false
},
mangle: false
}))
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(cssFilter.restore())
.pipe(rev())
.pipe(assets.restore())
.pipe(useref())
.pipe(revReplace())
.pipe(gulp.dest(dest));
});
gulp.task('htmlmin', function() {
return gulp.src('./dist/index.html')
.pipe(htmlmin({
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
}))
.pipe(gulp.dest('dist'));
});
gulp.task('default', ['clean'], function () {
runSequence('copy', 'build', 'htmlmin');
});