-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
133 lines (124 loc) · 3.52 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const gulp = require("gulp");
/*
gulp.src() 源路径
gulp.dest() 目的路径
pipe() 理解管道
*/
gulp.task("copy-html", function(){
return gulp.src("*.html")
.pipe(gulp.dest("dist"))
.pipe(connect.reload());
})
/*
图片
*/
gulp.task("images",function(){
return gulp.src(["*.{img,png,jpg}","images/*.{img,png,jpg}"])
.pipe(gulp.dest("dist/images"))
.pipe(connect.reload());
})
/*
js代码 jquery 不能压缩
*/
gulp.task("scripts", function(){
return gulp.src(["scripts/*.js","!gulpfile.js"])
.pipe(gulp.dest("dist/js"))
.pipe(connect.reload());
})
//数据
gulp.task("data", function(){
return gulp.src(["*.json", "json/*.json","!package.json"])
.pipe(gulp.dest("dist/json"))
.pipe(connect.reload());
})
/*
gulp-scss windows gulp-sass
gulp-minify-css
gulp-rename
【注】一个一个scss处理。
方向键 上 和下 可以控制控制台指令
*/
const sass = require("gulp-sass");
const minifyCSS = require("gulp-minify-css");
const rename = require("gulp-rename");
gulp.task("sass",function(){
return gulp.src("stylesheet/index.scss")
.pipe(sass())
.pipe(gulp.dest("dist/css"))
.pipe(minifyCSS())
.pipe(rename("index.min.css"))
.pipe(gulp.dest("dist/css"))
.pipe(connect.reload());
});
gulp.task("sass2",function(){
return gulp.src("stylesheet/stylereset.scss")
.pipe(sass())
.pipe(gulp.dest("dist/css"))
.pipe(minifyCSS())
.pipe(rename("stylereset.min.css"))
.pipe(gulp.dest("dist/css"))
.pipe(connect.reload());
})
gulp.task("sass3",function(){
return gulp.src("stylesheet/goods.scss")
.pipe(sass())
.pipe(gulp.dest("dist/css"))
.pipe(minifyCSS())
.pipe(rename("goods.min.css"))
.pipe(gulp.dest("dist/css"))
.pipe(connect.reload());
})
gulp.task("sass4",function(){
return gulp.src("stylesheet/product.scss")
.pipe(sass())
.pipe(gulp.dest("dist/css"))
.pipe(minifyCSS())
.pipe(rename("product.min.css"))
.pipe(gulp.dest("dist/css"))
.pipe(connect.reload());
})
gulp.task("sass5",function(){
return gulp.src("stylesheet/shopCar.scss")
.pipe(sass())
.pipe(gulp.dest("dist/css"))
.pipe(minifyCSS())
.pipe(rename("shopCar.min.css"))
.pipe(gulp.dest("dist/css"))
.pipe(connect.reload());
})
gulp.task("sass6",function(){
return gulp.src("stylesheet/design.scss")
.pipe(sass())
.pipe(gulp.dest("dist/css"))
.pipe(minifyCSS())
.pipe(rename("design.min.css"))
.pipe(gulp.dest("dist/css"))
.pipe(connect.reload());
})
//一次执行多个任务
gulp.task("build",["copy-html","images","sass","scripts","data","sass2","sass3","sass4","sass5","sass6"],function(){
console.log("项目链接成功");
})
//监听
gulp.task("watch", function(){
gulp.watch("*.html", ['copy-html']);
gulp.watch(["*.{img,png,jpg}","images/*.{img,png,jpg}"], ['images']);
gulp.watch([ "!gulpfile.js","scripts/*.js"], ['scripts']);
gulp.watch(["*.json", "!package.json","json/*.json"], ['data']);
gulp.watch("stylesheet/index.scss", ['sass']);
gulp.watch("stylesheet/stylereset.scss",['sass2']);
gulp.watch("stylesheet/goods.scss",['sass3']);
gulp.watch("stylesheet/product.scss",['sass4']);
gulp.watch("stylesheet/shopCar.scss",['sass5']);
gulp.watch("stylesheet/design.scss",['sass6']);
})
const connect =require("gulp-connect");
gulp.task("server",function(){
connect.server({
root:"dist",
port:8888,
livereload:true
})
})
//设置一个默认任务
gulp.task("default",["watch","server"]);