-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
87 lines (75 loc) · 2.1 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
87
const { series, watch, src, dest, parallel } = require('gulp')
const pump = require('pump')
// gulp plugins and utils
const livereload = require('gulp-livereload')
const postcss = require('gulp-postcss')
const zip = require('gulp-zip')
const uglify = require('gulp-uglify')
const sass = require('gulp-sass')(require('sass'))
// postcss plugins
const autoprefixer = require('autoprefixer')
const colorFunction = require('postcss-color-mod-function')
const cssnano = require('cssnano')
const easyimport = require('postcss-easy-import')
function serve(done) {
livereload.listen()
done()
}
const handleError = done => {
return err => {
return done(err)
}
}
function templates(done) {
pump(
[src(['*.hbs', '**/**/*.hbs', '!node_modules/**/*.hbs']), livereload()],
handleError(done)
)
}
function styles(done) {
const processors = [easyimport, colorFunction(), autoprefixer(), cssnano()]
pump(
[
src('styles/*.scss', { sourcemaps: true }),
sass({ outputStyle: 'compressed' }).on('error', sass.logError),
postcss(processors),
dest('assets/css/', { sourcemaps: '.' }),
livereload(),
],
handleError(done)
)
}
function scripts(done) {
pump(
[
src('scripts/*.js', { sourcemaps: true }),
uglify(),
dest('assets/js/', { sourcemaps: '.' }),
livereload(),
],
handleError(done)
)
}
function zipper(done) {
const targetDir = 'dist/'
const themeName = require('./package.json').name
const filename = `${themeName}.zip`
pump(
[
src(['**', '!node_modules', '!node_modules/**', '!dist', '!dist/**']),
zip(filename),
dest(targetDir),
],
handleError(done)
)
}
const stylesWatcher = () => watch('styles/**', styles)
const scriptsWatcher = () => watch(['scripts/**'], scripts)
const templatesWatcher = () =>
watch(['*.hbs', '**/**/*.hbs', '!node_modules/**/*.hbs'], templates)
const watcher = parallel(scriptsWatcher, stylesWatcher, templatesWatcher)
const build = series(styles, scripts)
const dev = series(build, serve, watcher)
exports.build = build
exports.zip = series(build, zipper)
exports.default = dev