-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
58 lines (49 loc) · 1.27 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
//引入gulp及gulp插件
var gulp = require("gulp"),
runSequence = require('run-sequence'),
rev = require('gulp-rev'),
revCollector = require('gulp-rev-collector'),
convertEncoding = require('gulp-convert-encoding');
//定义js源文件路径
var websiteJs = "js/website.js",
//css文件路径
websiteCss = "css/website.css",
websiteMobile = "css/websiteMobile.css";
var jsonArr = [websiteJs, websiteCss, websiteMobile];
//生成对应的json文件
//teskName:任务名称
//path:存储路径
function revFile(teskName, jsonArr, path) {
gulp.task(teskName, function() {
return gulp.src(jsonArr)
.pipe(rev())
.pipe(rev.manifest())
.pipe(gulp.dest(path));
});
}
var replacePath = ['rev/rev-manifest.json', './*.html'];
function replaceFile(teskName, replacePathArr, savePath) {
gulp.task(teskName, function() {
return gulp.src(replacePathArr)
.pipe(revCollector())
.pipe(convertEncoding({
iconv: {
decode: {},
encode: {
addBOM: true
}
},
to: "utf8"
}))
.pipe(gulp.dest(savePath));
});
}
revFile("revJson", jsonArr, "rev");
replaceFile("replaceJson", replacePath, "./");
//开发构建
gulp.task('dev', function(done) {
condition = false;
runSequence(
['revJson'], ['replaceJson'], done);
});
gulp.task('default', ['dev']);