-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
70 lines (65 loc) · 1.91 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
var gulp = require("gulp");
var imagemin = require("gulp-imagemin");
var newer = require("gulp-newer");
var htmlclean = require("gulp-htmlclean");
var uglify = require("gulp-uglify");
var stripDebug = require("gulp-strip-debug");//去掉js中的调试语句
var concat = require("gulp-concat");//整合所有js文件
var less = require("gulp-less");
var postcss = require("gulp-postcss");//整合css
var autopre = require("autoprefixer");//添加兼容前綴
var cssnano = require("cssnano");//壓縮css代碼
var connect = require("gulp-connect");
var devMode = process.env.NODE_ENV == "development";
var folder = {
src:"./src/",
build:"./build/"
}
//流读取文件
gulp.task("img",function(){
gulp.src(folder.src + "img/*")
.pipe(newer(folder.build + "img"))
.pipe(imagemin())
.pipe(gulp.dest(folder.build + "img"))
})
gulp.task("html",function(){
var page = gulp.src(folder.src + "html/*")
.pipe(connect.reload())
if(!devMode){
page.pipe(htmlclean())
}
page.pipe(gulp.dest(folder.build + "html"))
})
gulp.task("js",function(){
var page = gulp.src(folder.src + "js/*")
.pipe(connect.reload())
if(!devMode){
page.pipe(stripDebug())
.pipe(uglify())
}
page.pipe(gulp.dest(folder.build + "js"))
})
gulp.task("css",function(){
var options = [autopre(),cssnano()]
var page = gulp.src(folder.src + "css/*")
.pipe(less())
.pipe(connect.reload())
if(!devMode){
page.pipe(postcss(options))
}
page.pipe(gulp.dest(folder.build + "css"))
})
gulp.task("watch",function(){
gulp.watch(folder.src + "html/*", ["html"]);
gulp.watch(folder.src + "css/*",["css"]);
gulp.watch(folder.src + "js/*",["js"]);
gulp.watch(folder.src + "img/*", ["img"]);
})
gulp.task("server",function(){
connect.server({
port:"8090",
livereload: true//开启浏览器自动刷新
});
})
gulp.task("default",["img","html","js","css","watch","server"],function(){
})