-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile-build.js
69 lines (61 loc) · 1.53 KB
/
gulpfile-build.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
// 加载模块
const {task,src,dest,watch,series,parallel} = require('gulp');
// 用于加载其他gulp插件
const load = require('gulp-load-plugins')();
// nodejs的del模块用于删除文件
const del = require('del');
// 删除dist目录
task('delDist',async ()=>{
await del('./dist');
})
// 处理图片
task('image', async ()=>{
src('./image/*.*')
.pipe(dest('./dist/image'))
})
// 处理sass
task('sass', async ()=>{
src('./sass/*.scss')
.pipe(load.sassChina())
.pipe(load.rev())
.pipe(load.minifyCss())
.pipe(dest('./dist/css'))
.pipe(load.rev.manifest())
.pipe(dest('./rev/css'))
})
// 处理js
task('script', async ()=>{
src('./script/*.js')
.pipe(load.rev())
.pipe(load.babel({presets: ['@babel/env']}))
.pipe(load.uglify())
.pipe(dest('./dist/script'))
.pipe(load.rev.manifest())
.pipe(dest('./rev/js'))
})
// 处理html
task('html', async ()=>{
setTimeout(()=>{
src(['./rev/**/*.json','./pages/*.html'])
.pipe(load.revCollector({replaceReved:true}))
.pipe(load.minifyHtml())
.pipe(dest('./dist/pages'))
},1000);
})
// 监听文件变化
// task('watch',async ()=>{
// watch('./image/*.*',series('image'));
// watch('./style/*.css',series('style'));
// watch('./script/*.js',series('script'));
// watch('./pages/*.html',series('html'));
// })
// 启动服务,自动刷新
task('connect',async ()=>{
load.connect.server({
root: './dist',
livereload: true,
port: 3001
});
})
// 构建生产包
task('build',series('delDist','image','sass','script','html','connect'))