-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgulpfile.js
67 lines (59 loc) · 2.03 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
var gulp = require('gulp');
var htmlmin = require('gulp-htmlmin');
var jsmin = require('gulp-jsmin');
var rename = require('gulp-rename');
var imagemin = require('gulp-imagemin');
var tinypng = require('gulp-tinypng-compress');
var tiny = require('gulp-tinypng-nokey');
var pngquant = require('imagemin-pngquant');
var csso = require('gulp-csso');
var root = "./";
var buildDir = root;
var datas = {
html: [root + "/**/**/*.html", '!node_modules/**', '!.idea/**', '!themes/**'],
image: [root + "/**/*.{png,jpg,jpeg}", '!node_modules/**', '!themes/**', '!themes/**'],
css: [root + "/**/*.css", '!node_modules/**', '!themes/**'],
js: [root + "/**/*.js", '!*min.js', '!node_modules/**', '!themes/**', '!gulpfile.js']
}
gulp.task("htmlmin", function () {
gulp.src(datas.html).pipe(htmlmin({
collapseWhitespace: true,
minifyJS: true,
minifyCSS: true,
removeComments: true
})).pipe(gulp.dest(buildDir));
});
gulp.task("imagemin", function () {
gulp.src(datas.image).pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
})).pipe(gulp.dest(buildDir));
});
gulp.task("tinypng", function () {
gulp.src(datas.image).pipe(tinypng({
key: 'Wfz4fyNBcSJQErzUiVcski2K6mt3_KvO',
sigFile: root + 'images/.tinypng-sigs',
log: true,
sameDest: true
})).pipe(gulp.dest(buildDir));
});
gulp.task("tiny", function () {
gulp.src(datas.image)
.pipe(tiny())
.pipe(gulp.dest(buildDir));
});
gulp.task("jsmin", function () {
gulp.src(datas.js).pipe(jsmin()).pipe(gulp.dest(buildDir));
});
gulp.task("cssmin", function () {
gulp.src(datas.css).pipe(csso()).pipe(gulp.dest(buildDir));
});
gulp.task("default", ["htmlmin",
"tinypng",
"jsmin", "cssmin"]);
// gulp.task("default", ["htmlmin", "jsmin", "cssmin"]);
// gulp.task("default", ["tinypng"]);
// gulp.task("default", ["tiny"]);
//gulp.task("default", ["imagemin", "jsmin"]); // TODO htmlmin 报错
// gulp.task("default", ["htmlmin", "jsmin"]);