-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
80 lines (68 loc) · 1.99 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
const { src, dest, series, parallel, watch } = require('gulp')
const webpack = require('webpack')
const browserSync = require('browser-sync').create()
const del = require('del')
const webpackDevConfig = require('./webpack.dev.js')
const webpackProdConfig = require('./webpack.prod.js')
// Clean distribution directory
const clean = () => del('dist/**')
// Bundling TS
const bundle = (config) => () => {
return new Promise((resolve, reject) => {
webpack(config, (error, stats) => {
if (error) {
return reject(error)
}
if (stats.hasErrors()) {
return reject(new Error(stats.compilation.errors.join('\n')))
}
resolve()
})
})
}
const devBundle = bundle(webpackDevConfig)
devBundle.displayName = 'dev-bundle'
const prodBundle = bundle(webpackProdConfig)
prodBundle.displayName = 'prod-bundle'
// Copying files
const css = () => src('src/css/*').pipe(dest('dist/'))
const assets = () => src('src/img/*').pipe(dest('dist/img/'))
const html = () => src('src/*.html').pipe(dest('dist/'))
const config = () => src('src/_headers').pipe(dest('dist/'))
// Watching files
const watchFiles = () => {
watch('src/css/*', series(css, reload))
watch('src/img/*', series(assets, reload))
watch('src/*.html', series(html, reload))
watch('src/**/*.ts', series(devBundle, reload))
}
// Serving files
const serve = (done) => {
browserSync.init({
server: './dist',
port: 8080,
}, done)
}
const serveAndWatch = (done) => {
browserSync.init({
server: './dist',
port: 8080,
}, done)
watchFiles()
}
serveAndWatch.displayName = 'serve-and-watch'
const reload = (done) => {
browserSync.reload()
done()
}
// Creating production bundle
const productionBuild = series(
prodBundle,
parallel(css, assets, html, config),
)
exports.clean = clean
exports.copy = parallel(css, assets, html, config)
exports.build = productionBuild
exports.serve = serve
exports.develop = series(devBundle, parallel(css, assets, html), serveAndWatch)
exports.watch = watchFiles