/
gulpfile.babel.js
104 lines (92 loc) · 1.84 KB
/
gulpfile.babel.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
import del from 'del'
import pug from 'gulp-pug'
import stylus from 'gulp-stylus'
import cleanCss from 'gulp-clean-css'
import autoprefixer from 'gulp-autoprefixer'
import babel from 'gulp-babel'
const { src, dest, series, parallel, watch } = require('gulp')
const browsersync = require('browser-sync').create()
const config = {
src: {
root: './src',
html: './src/**/*pug',
style: './src/style/**/*.styl',
script: './src/script/**/*.js'
},
dist: {
root: './dist',
style: './dist/style',
script: './dist/script'
}
}
const targetBrowser = {
'presets': [
['@babel/preset-env', {
'targets': {
'browsers': [
'>0.25%',
'not ie 11'
]
}
}]
]
}
// BrowserSync
const browserSync = cb => {
browsersync.init({
server: {
baseDir: config.dist.root
},
port: 3000
})
cb()
}
const reload = cb => {
browsersync.reload()
cb()
}
const clean = cb => {
del(config.dist.root)
cb()
}
const html = cb => {
console.log('Task: HTML')
const option = {
pretty: true
}
src(config.src.html)
.pipe(pug(option))
.pipe(dest(config.dist.root))
cb()
}
const css = cb => {
console.log('Task: CSS')
src(
config.src.style,
{
ignore: ['**/_*.styl']
}
)
.pipe(stylus())
.pipe(cleanCss())
.pipe(autoprefixer(targetBrowser))
.pipe(dest(config.dist.style))
cb()
}
const script = cb => {
console.log('Task: JavaScript')
src(config.src.script)
.pipe(babel())
.pipe(dest(config.dist.script))
cb()
}
// Watch files
const watchFiles = () => {
watch(config.src.html, series(html, reload))
watch(config.src.style, css)
watch(config.src.script, script)
}
// definition tasks
exports.clean = clean
exports.build = series(clean, parallel(html, css, script))
exports.default = parallel(watchFiles, browserSync)