-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
86 lines (78 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
// modules
const fs = require('fs')
const bsync = require('browser-sync').create()
const webpack = require('webpack-stream')
const autoprefixer = require('autoprefixer')
// gulp
const { src, dest, series, parallel, watch } = require('gulp')
// gulp plugins
const pug = require('gulp-pug')
const sass = require('gulp-sass')(require('sass'))
const data = require('gulp-data')
const rename = require('gulp-rename')
const replace = require('gulp-replace')
const postcss = require('gulp-postcss')
const cleanCSS = require('gulp-clean-css')
const sourcemaps = require('gulp-sourcemaps')
const urlBuilder = require('gulp-url-builder')
const htmlbeautify = require('gulp-html-beautify')
// variables & config
const destination = 'docs'
const webpackOptions = { mode: 'production' }
const locals = {}
// pug
function pugCompile() {
return src([
'src/pug/views/**/*.pug'
]).pipe( pug({ locals }) )
.pipe( htmlbeautify({ indent_size: 2 }) )
.pipe( urlBuilder() )
.pipe( dest(destination) )
.pipe( bsync.reload({ stream: true }) )
}
function pugWatch(cb) {
watch(['src/pug/**/*.pug'], pugCompile)
cb()
}
// sass
function sassCompile() {
return src([
'src/scss/**/*.+(sass|scss|css)',
'!src/scss/**/_*.*'
]).pipe( sass({ includePaths: ['node_modules'] }) )
.pipe( postcss([ autoprefixer() ]) )
.pipe( cleanCSS() )
.pipe( dest(`${destination}/css`) )
.pipe( bsync.reload({ stream: true }) )
}
function sassWatch(cb) {
watch(['src/scss/**/*.*'], sassCompile)
cb()
}
// javascript
function jsBundle() {
return src('src/js/app.js')
.pipe( webpack(webpackOptions) )
.pipe( rename({ basename: 'app' }) )
.pipe( dest(`${destination}/js`) )
.pipe( bsync.reload({ stream: true }) )
}
function jsWatch(cb) {
watch('src/js/**/*.js', jsBundle)
cb()
}
// browsersync
function sync() {
bsync.init({
server: {
baseDir: `./${destination}`
}
})
}
// exports
exports.pug = pugCompile
exports.sass = sassCompile
exports.js = jsBundle
exports.build = series(exports.pug, exports.sass, exports.js)
exports.watch = series(pugWatch, sassWatch, jsWatch)
exports.default = series(exports.build, exports.watch, sync)