-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
98 lines (87 loc) · 2.2 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
let gulp = require('gulp')
let less = require('gulp-less')
let connect = require('gulp-connect')
let template = require('gulp-template')
let imgmin = require('gulp-imagemin')
let cssmin = require('gulp-clean-css')
let jsmin = require('gulp-uglify')
let autofixer = require('gulp-autoprefixer')
let indexcss = 'css/index.css'
let listcontentcss = 'css/listcontent.css'
gulp.task('connect', () => {
connect.server({
root: 'dist/',
livereload: true
})
})
// 开启服务器
gulp.task('reloadhtml', () => {
gulp.src('./dist/index.html')
.pipe(connect.reload())
})
// 重载页面
gulp.task('cpfont', () => {
gulp.src('src/font/**/*.*')
.pipe(gulp.dest('dist/font'))
})
gulp.task('indexhtml', () => {
gulp.src('./src/index.html')
.pipe(template({indexcss: indexcss}))
.pipe(gulp.dest('dist/'))
})
// 复制 src/index -> dist/html
gulp.task('listcontenthtml', () => {
gulp.src(['src/list.html','src/content.html'])
.pipe(template({ listcontentcss: listcontentcss}))
.pipe(gulp.dest('dist/'))
})
// list+content html
gulp.task('wacthhtml', () => {
gulp.watch('./src/index.html', ['indexhtml','reloadhtml'])
gulp.watch(['./src/list.html','src/content.html'], ['listcontenthtml'])
})
// 监听 index 刷新html
gulp.task('img', () => {
gulp.src('src/img/**/*.*')
.pipe(imgmin({
progressive: true
}))
.pipe(gulp.dest('dist/img'))
})
// 压缩图片
gulp.task('watchimg', () => {
gulp.watch('src/img/**/*.*',['img','reloadhtml'])
})
// 监听 图片文件夹
gulp.task('less', () => {
gulp.src(['src/less/index.less','src/less/listcontent.less'])
.pipe(less())
.pipe(cssmin({ compatibility: 'ie8' }))
.pipe(autofixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('dist/css'))
})
// 编译less
gulp.task('watchless', () => {
gulp.watch('src/less/**/*.less', ['less','reloadhtml'])
})
// 监听less
gulp.task('js', () => {
gulp.src('src/js/**/*.js')
.pipe(jsmin())
.pipe(gulp.dest('dist/js'))
})
// 压缩js
gulp.task('watchjs', () => {
gulp.watch('src/js/**/*.js', ['js','reloadhtml'])
})
// 监听 Js
gulp.task('default', [
// reload
'indexhtml', 'img', 'less', 'js', 'cpfont', 'connect',
// Watch
'wacthhtml', 'watchless', 'watchjs'
]
)