-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
106 lines (93 loc) · 2.22 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
99
100
101
102
103
104
105
106
import gulp from 'gulp'; const { src, dest, watch, series, parallel } = gulp
import del from 'del'
import include from 'gulp-file-include'
import htmlmin from 'gulp-htmlmin'
import autoPrefixer from 'gulp-autoprefixer'
import concat from 'gulp-concat'
import pxtorem from 'gulp-pxtorem'
import csso from 'gulp-csso'
import replace from 'gulp-replace'
import babel from 'gulp-babel'
import uglify from 'gulp-uglify'
import { stream, init, reload, create } from 'browser-sync'
const html = () => src(['src/**/*.html', '!src/**/_*.html'])
.pipe(include())
.pipe(htmlmin({
collapseWhitespace: true
}))
.pipe(dest('dist'))
.pipe(stream())
const css = async () => {
const concatinate = [
'src/css/preset.css',
// 'src/css/variables.css',
'src/css/fonts.css',
'src/css/main.css',
'src/css/media.css'
]
src(concatinate)
.pipe(concat('main.css'))
.pipe(autoPrefixer())
.pipe(pxtorem({
rootValue: 12,
unitPrecision: 4,
propList: ['*']
}))
.pipe(replace(/Px|PX|pX/g, 'px'))
.pipe(csso())
.pipe(dest('dist/css'))
.pipe(stream())
const other = concatinate.map(el => '!' + el)
src([
'src/css/**/*.css',
...other
])
// .pipe(concat('style.css'))
.pipe(autoPrefixer())
.pipe(pxtorem({
rootValue: 12,
unitPrecision: 4,
propList: ['*']
}))
.pipe(replace(/Px|PX|pX/g, 'px'))
.pipe(csso())
.pipe(dest('dist/css'))
.pipe(stream())
}
const js = () => src('src/js/**/*.js')
.pipe(babel({
presets: ['@babel/env']
}))
// .pipe(concat('script.js'))
.pipe(uglify())
.pipe(dest('dist/js'))
.pipe(stream())
const img = () => src('src/img/**/*')
.pipe(dest('dist/img'))
.pipe(stream())
const fonts = () => src('src/fonts/**/*')
.pipe(dest('dist/fonts'))
.pipe(stream())
const serve = () => {
create()
init({
server: {
baseDir: 'dist'
}
})
watch('src/**/*.html', html).on('change', reload)
watch('src/css/**/*.css', css)
watch('src/js/**/*.js', js)
watch('src/img/**/*', img)
watch('src/fonts/**/*', fonts)
}
export const clean = () => del('dist')
export default series(
clean,
parallel(css, js, img, fonts, html),
serve
)
export const build = series(
clean,
parallel(css, js, img, fonts, html)
)