-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
54 lines (48 loc) · 1.34 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
import fs from 'fs'
import gulp from 'gulp'
import babel from 'gulp-babel'
import uglify from 'gulp-uglify'
import rename from 'gulp-rename'
import sass from 'gulp-sass'
import foreach from 'gulp-foreach'
import insert from 'gulp-insert'
import cleanCss from 'gulp-clean-css'
sass.compiler = require('node-sass')
const paths = {
scripts: [
'src/**/*.js',
'!src/**/build/*.js'
],
styles: [
'src/**/*.scss',
'!src/_includes/_assets/styles/_settings.scss',
],
}
export function scripts () {
return gulp.src(paths.scripts)
.pipe(babel())
.pipe(uglify())
.pipe(rename(path => {path.dirname += '/build'}))
.pipe(gulp.dest(file => file.base))
}
export function styles () {
const sassSettings = fs.readFileSync('src/_includes/_assets/styles/_settings.scss')
return gulp.src(paths.styles)
.pipe(foreach(stream => {
return stream
.pipe(insert.prepend(sassSettings))
.pipe(sass().on('error', sass.logError))
.pipe(cleanCss())
.pipe(rename(path => {path.dirname += '/build'}))
.pipe(gulp.dest(file => file.base))
}))
}
export function watch () {
gulp.watch(paths.scripts, scripts)
gulp.watch('src/_includes/_assets/styles/_settings.scss', styles)
gulp.watch(paths.styles, gulp.series(styles))
}
/*
* Export a default task
*/
export default gulp.series(scripts, styles)