-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (67 loc) · 1.8 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
const { src, dest, parallel, series, watch } = require('gulp')
const rev = require('gulp-rev')
const revRewrite = require('gulp-rev-rewrite')
const del = require('delete')
const replace = require('gulp-replace-path')
const cleanCss = require('gulp-clean-css')
const cleanJs = require('gulp-uglify')
const cleanHtml = require('gulp-htmlmin')
const babel = require('gulp-babel')
// 位置
let distPath = 'assets'
function toDel (cb) {
del(['dist'], cb)
}
// css部分
function css (cb) {
return src('style/*.css')
.pipe(cleanCss())
.pipe(dest('dist/' + distPath + '/style'))
}
// js
function js (cb) {
return src('js/*.js')
.pipe(
babel({
presets: ['@babel/env']
})
)
.pipe(cleanJs())
.pipe(dest('dist/' + distPath + '/js'))
}
// html
function html (cb) {
return (
src('index.html')
.pipe(replace(/\b((src|href)=(\"|'))(?!http)/g, `$1${distPath}/`))
.pipe(cleanHtml({ collapseWhitespace: true }))
.pipe(dest('dist'))
)
}
// build 部分👇
// 去添加指纹
function toManifest (cb) {
del(['manifest', 'build'])
return src(`dist/${distPath}/**/*`)
.pipe(rev())
.pipe(dest(`build/${distPath}`))
.pipe(rev.manifest())
.pipe(dest('manifest'))
}
// rewrite rev
function replaceName (cb) {
let manifest = src('manifest/rev-manifest.json')
return src(`dist/index.html`)
.pipe(revRewrite({ manifest }))
.pipe(dest('build'))
}
// 监视文件变化
function adminIt () {
watch('style/**/*.css', css)
watch('js/**/*.js', js)
watch('index.html', html)
}
exports.admin = adminIt
exports.assets = parallel(css, js, html)
exports.default = series(toDel, parallel(css, js, html))
exports.build = series(toDel, parallel(css, js, html), toManifest, replaceName)