-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·99 lines (79 loc) · 1.88 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var gulp=require("gulp"),
concat=require("gulp-concat"),
jshint=require("gulp-jshint"),
compass = require('gulp-compass'),
uglify=require("gulp-uglify"),
browserSync=require("browser-sync"),
RevAll=require("gulp-rev-all"),
clean=require("gulp-clean")
cdn=[
"http://res.m.yystatic.com/",
"http://res0.m.yystatic.com/",
"http://res1.m.yystatic.com/"
]
gulp.task("js",function(){
return gulp.src("src/js/*.js")
.pipe(jshint())
// .pipe(concat("main.js"))
.pipe(uglify())
.pipe(gulp.dest("dest/js"))
})
gulp.task('sass', function() {
gulp.src('src/sass/*.scss')
.pipe(compass({
config_file: 'config.rb',
sass: 'src/sass'
}))
.pipe(gulp.dest('dest/css'));
});
gulp.task("html",function(){
return gulp.src("src/html/*.html")
.pipe(gulp.dest("dest/html"))
})
gulp.task("img",function(){
return gulp.src("src/image/*.+(jpg|png|gif)")
.pipe(gulp.dest("dest/image"))
})
gulp.task("clean",function(){
gulp.src("publish",{read: false})
.pipe(clean())
})
gulp.task("browser-sync",function(){
var files=[
"dest/css/*.css",
"dest/html/*.html",
"dest/js/*.js"
]
browserSync.init(files,{
server:{
baseDir:"dest"
}
})
})
gulp.task("static",["img","html","sass","js"])
gulp.task("watch",function(){
gulp.watch("src/**/*",["static"])
})
gulp.task("dev",["static","browser-sync","watch"],function(){
console.log("开发模式已启动!")
})
gulp.task("publish",["clean"],function(){
var _indexCopy=0
var revAll=new RevAll({
dontRenameFile: ['.html'],
hashLength: 8,
transformPath: function (rev, source, path) {
var _index=(++_indexCopy)%cdn.length
return rev.replace('../', cdn[_index]);
}
})
gulp.src("dest/**")
.pipe(revAll.revision())
.pipe(gulp.dest("publish"))
.pipe(revAll.manifestFile())
.pipe(gulp.dest("publish"))
console.log("发布完成,可以上线!")
})
function test(){
var name=gulp2;
}