-
Notifications
You must be signed in to change notification settings - Fork 20
/
gulpfile.js
70 lines (58 loc) · 1.66 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
const { spawn } = require('child_process')
const { dest, series, src, watch } = require('gulp')
const log = require('fancy-log')
const less = require('gulp-less')
const LessAutoprefix = require('less-plugin-autoprefix')
const cleanCSS = require('gulp-clean-css')
const hugoBin = require('hugo-bin')
const BrowserSync = require('browser-sync')
const webpack = require('webpack')
const webpackConfig = require('./webpack.config')
const browserSync = BrowserSync.create()
const autoprefix = new LessAutoprefix({ browsers: ['last 2 versions'] })
function buildCss() {
return src('./src/less/**/*.less')
.pipe(less({ plugins: [autoprefix] }))
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(dest('./dist/css'))
.pipe(browserSync.stream())
}
function buildJsAndTpl(cb) {
webpack(webpackConfig, (_, stats) => {
log(
'Webpack',
stats.toString({
colors: true,
})
)
cb()
})
}
const hugoArgsDefault = ['-d', './dist', '-s', '.', '-v']
function buildSite(cb, options = []) {
const args = options ? hugoArgsDefault.concat(options) : hugoArgsDefault
spawn(hugoBin, args, { stdio: 'inherit' }).on('close', () => {
if (process.env.NODE_ENV === 'development') {
browserSync.reload()
}
cb()
})
}
exports.build = series(buildCss, buildJsAndTpl, buildSite)
exports.buildJsAndTpl = buildJsAndTpl
exports.server = () => {
browserSync.init({
host: '0.0.0.0',
ui: {
port: 4000,
},
port: 3005,
server: {
baseDir: './dist',
},
online: true,
})
watch('./src/js/**/*.js', buildJsAndTpl)
watch('./src/less/**/*.less', buildCss)
watch('./{data,content,layouts,static}/**/*', buildSite)
}