-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
70 lines (66 loc) · 1.86 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
const gulp = require("gulp");
const htmlmin = require("gulp-htmlmin");
const uglify = require("gulp-uglify");
const babel = require("gulp-babel");
const connect = require("gulp-connect");
const sass = require("gulp-sass");
const cleanCss = require("gulp-clean-css");
//压缩html
gulp.task("html",()=>{
gulp.src("src/**/*.html")
.pipe(htmlmin({
removeComments: true,//清除HTML注释
collapseWhitespace: true,//压缩HTML
collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
}))
.pipe(gulp.dest("dist"))
.pipe(connect.reload());
})
//压缩js
gulp.task("js",()=>{
gulp.src("src/js/**/*.js")
//es6转es5
.pipe(babel({
presets:['@babel/env']
}))
.pipe(uglify())
.pipe(gulp.dest("dist/js"))
.pipe(connect.reload());
})
//编译sass
//压缩css
gulp.task("css",()=>{
gulp.src("src/scss/**/*.scss")
.pipe(sass())
.pipe(cleanCss())
.pipe(gulp.dest("dist/css"))
})
//开启server
gulp.task("server",()=>{
connect.server({
port:2000,
livereload:true,
root:"dist"
})
})
//移动libs
gulp.task("libs",()=>{
gulp.src("src/libs/**/*")
.pipe(gulp.dest("dist/libs"));
})
//移动静态资源
gulp.task("static",()=>{
gulp.src("src/static/**/*")
.pipe(gulp.dest("dist/static"))
.pipe(connect.reload());
})
//监听文件改变
gulp.task("watch",()=>{
gulp.watch("src/**/*.html",["html"]);
gulp.watch("src/js/**/*.js",["js"]);
gulp.watch("src/scss/**/*.scss",["css"])
})
gulp.task("default",["server","html","js","static","css","libs","watch"]);