-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
59 lines (56 loc) · 1.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
const { watch, src, dest } = require('gulp')
const del = require('del')
const copy = path => {
let allFile = path.split('/')
let watchFile = allFile[0] // 获得监听的根文件
let changeFile = allFile[allFile.length - 1] // 获得改变的文件
let distPash = path.replace(watchFile, '').replace(changeFile, '') //压缩的文件路径
if (allFile.includes('views')) {
let topath = allFile.includes('pc_test') ? 'pc' : 'mobile'
return src(path).pipe(dest(`${topath}/template${distPash}`))
} else {
return src(path).pipe(dest('default' + distPash))
}
}
const delfile = path => {
let allFile = path.split('/')
let watchFile = allFile[0]
let distPash = path.replace(watchFile, '')
if (allFile.includes('views')) {
let topath = allFile.includes('pc_test') ? 'pc' : 'mobile'
del(`${topath}/template${distPash}`)
} else {
del('default' + distPash)
}
}
const pcTask = () => {
console.log('监听pc_test....')
const watcher = watch(['./pc_test/**/*'])
watcher.on('change', path => {
delfile(path)
copy(path)
})
watcher.on('add', path => {
copy(path)
})
watcher.on('unlink', path => {
delfile(path)
})
}
const mobileTask = () => {
console.log('监听mobile_test....')
const watcher = watch(['./mobile_test/**/*'])
watcher.on('change', path => {
delfile(path)
copy(path)
})
watcher.on('add', path => {
copy(path)
})
watcher.on('unlink', path => {
delfile(path)
})
}
exports.default = pcTask
exports.pcTask = pcTask
exports.mobileTask = mobileTask