-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.js
52 lines (43 loc) · 1.06 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
const gulp = require('gulp')
const gutil = require('gulp-util')
const babel = require('gulp-babel')
const plumber = require('gulp-plumber')
const dirname = require('path').dirname
const srcdir = __dirname + '/src'
const destdir = __dirname + '/dist'
/**
* 1. transpile all babel files
* 2. watch src dir
* 3. transpile on changed
*/
gulp.task('watch', x => {
gulp.start('babel:all')
gulp.watch('src/**/*.js', (info) => {
const src = info.path
const relpath = src.slice(srcdir.length + 1)
const dest = destdir + '/' + dirname(relpath)
gutil.log(`[${info.type}]: ${relpath}`)
compileBabel(src, dest)
.on('end', x => {
gutil.log(`compilation finished: ${dest}`)
})
})
})
/**
* transpile all babel files
*/
gulp.task('babel:all', x => {
compileBabel('src/**/*.js', 'dist')
.on('end', x => {
gutil.log('compilation finished: all js files.')
})
})
/**
* transipile babel src to dest
*/
function compileBabel(src, dest) {
return gulp.src(src)
.pipe(plumber())
.pipe(babel())
.pipe(gulp.dest(dest))
}