This repository has been archived by the owner on Nov 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
executable file
·104 lines (88 loc) · 2.73 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
'use strict'
import gulp from 'gulp'
import del from 'del'
import runSequence from 'run-sequence'
import gulpLoadPlugins from 'gulp-load-plugins'
import { spawn } from "child_process"
import tildeImporter from 'node-sass-tilde-importer'
const $ = gulpLoadPlugins()
const browserSync = require('browser-sync').create()
const isProduction = process.env.NODE_ENV === 'production'
const onError = (err) => {
console.log(err)
}
// --
gulp.task('server', ['build'], () => {
browserSync.init({
server: {
baseDir: 'public'
},
open: false
})
$.watch('src/sass/**/*.scss', () => gulp.start('sass'))
$.watch('src/js/**/*.js', () => gulp.start('js-watch'))
$.watch('src/images/**/*', () => gulp.start('images'))
$.watch(['archetypes/**/*', 'data/**/*', 'content/**/*', 'layouts/**/*', 'static/**/*', 'config.toml'], () => gulp.start('hugo'))
});
gulp.task('build', () => {
runSequence(['sass', 'js', 'fonts', 'images'], 'hugo')
})
gulp.task('build-preview', () => {
runSequence(['sass', 'js', 'fonts', 'images'], 'hugo-preview')
})
gulp.task('hugo', (cb) => {
return spawn('hugo', { stdio: 'inherit' }).on('close', (code) => {
browserSync.reload()
cb()
})
})
gulp.task('hugo-preview', (cb) => {
return spawn('hugo', ['--buildDrafts', '--buildFuture'], { stdio: 'inherit' }).on('close', (code) => {
browserSync.reload()
cb()
})
})
// --
gulp.task('sass', () => {
return gulp.src([
'src/sass/**/*.scss'
])
.pipe($.plumber({ errorHandler: onError }))
.pipe($.print())
.pipe($.sass({ precision: 2, importer: tildeImporter }))
.pipe($.autoprefixer(['ie >= 10', 'last 2 versions']))
.pipe($.if(isProduction, $.cssnano({ discardUnused: false, minifyFontValues: false })))
.pipe($.size({ gzip: true, showFiles: true }))
.pipe(gulp.dest('static/css'))
.pipe(browserSync.stream())
})
gulp.task('js-watch', ['js'], (cb) => {
browserSync.reload();
cb();
});
gulp.task('js', () => {
return gulp.src([
'src/js/**/*.js'
])
.pipe($.plumber({ errorHandler: onError }))
.pipe($.print())
.pipe($.babel())
.pipe($.concat('app.js'))
.pipe($.if(isProduction, $.uglify()))
.pipe($.size({ gzip: true, showFiles: true }))
.pipe(gulp.dest('static/js'))
})
gulp.task('fonts', () => {
return gulp.src('src/fonts/**/*.{woff,woff2}')
.pipe(gulp.dest('static/fonts'));
});
gulp.task('images', () => {
return gulp.src('src/images/**/*.{png,jpg,jpeg,gif,svg,webp}')
.pipe($.newer('static/images'))
.pipe($.print())
.pipe($.imagemin())
.pipe(gulp.dest('static/images'));
});
gulp.task('cms-delete', () => {
return del(['static/admin'], { dot: true })
})