/
gulpfile.js
59 lines (53 loc) · 1.85 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
/**
* @fileoverview gulpfile example
* @author javey
* @date 14-12-22
*/
var gulp = require('gulp'),
nocache = require('../src/index.js');
gulp.task('build_image', function() {
// 返回stream保证任务完成再进行下一个任务
return gulp.src('./web/edit.png')
.pipe(nocache({
type: 'media', // 可选取值:media/css/js/tpl
dest: './build/[path][name].[hash:6].[ext]',
sourceContext: './web',
outputContext: './build'
}))
// 保存文件到nocache返回的路径中
.pipe(gulp.dest(function(file) {return file.base}));
});
gulp.task('build_css', ['build_image'], function() {
return gulp.src('./web/main.css')
.pipe(nocache({
type: 'css',
dest: './build/[path][name].[hash:6].[ext]',
sourceContext: './web',
outputContext: './build',
cdn: ['//s1.static.com', '//s2.static.com']
}))
.pipe(gulp.dest(function(file) {return file.base}));
});
gulp.task('build_js', ['build_image'], function() {
return gulp.src('./web/**/*.js')
.pipe(nocache({
type: 'js',
dest: './build/[path][name].[hash:6].[ext]',
sourceContext: './web',
outputContext: './build',
cdn: ['//s1.static.com', '//s2.static.com']
}))
.pipe(gulp.dest(function(file) {return file.base}));
});
gulp.task('build_tpl', ['build_image', 'build_css', 'build_js'], function() {
return gulp.src('./web/index.html')
.pipe(nocache({
type: 'tpl',
dest: './build/[path][name].[ext]',
sourceContext: './web',
outputContext: './build',
cdn: ['//s1.static.com', '//s2.static.com']
}))
.pipe(gulp.dest(function(file) {return file.base}));
});
gulp.task('default', ['build_tpl']);