-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
63 lines (55 loc) · 1.42 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
'use strict'
// Sets up variables
const { series, watch, src, dest, parallel } = require('gulp')
const sass = require('gulp-sass')(require('sass'))
const sourcemaps = require('gulp-sourcemaps')
const pug = require('gulp-pug')
const prettier = require('gulp-prettier')
const browserSync = require('browser-sync').create()
const postcss = require('gulp-postcss')
const autoprefixer = require('autoprefixer')
// Browser Sync
function serve(done) {
browserSync.init({
server: {
baseDir: 'dist',
},
port: 3000,
open: false,
})
done()
}
// Sass compiler
function css() {
return src('src/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(
sass({
outputStyle: 'expanded',
}).on('error', sass.logError)
)
.pipe(sourcemaps.write('.'))
.pipe(dest('dist/css'))
.pipe(browserSync.stream())
}
// HTML compiler
function html() {
return src('src/pug/**/!(_)*.pug').pipe(pug()).pipe(dest('dist')).pipe(browserSync.stream())
}
// Build CSS
function buildCSS() {
return src('dist/css/**/*.css')
.pipe(postcss([autoprefixer()]))
.pipe(prettier())
.pipe(dest('dist/css'))
}
// Build HTML
function buildHTML() {
return src('dist/**/*.html').pipe(prettier()).pipe(dest('dist'))
}
// Watch
function watcher() {
watch(['src/scss/**/*.scss', 'src/pug/**/*.pug'], parallel(css, html))
}
exports.default = parallel(serve, watcher)
exports.build = parallel(buildCSS, buildHTML)