forked from codymikol/karma-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
69 lines (61 loc) · 1.55 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
'use strict' // eslint-disable-line strict
const gulp = require('gulp')
const del = require('del')
const util = require('gulp-util')
const eslint = require('gulp-eslint')
const babel = require('gulp-babel')
gulp.task('clean', function(done) {
del([
'lib/**/*',
])
done()
})
/**
* Lints all the JavaScript in the project.
* Ignores transpiled code & node_modules.
*/
gulp.task('lint', function(done) {
gulp.src(['**/*.js', '!node_modules/**', '!lib/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
done()
})
/**
* Transpiles with Babel based on defined presets.
*/
gulp.task('build', function(done) {
gulp.src('src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('lib'))
done()
})
/**
* Watches for changes in the src directory.
* "on change" transpiles incrementally.
* "on unlink" removes the transpiled version of the deleted file.
*/
gulp.task('watch', function() {
gulp.watch('src/**/*.js')
.on('change', function(path) {
gulp.src(path)
.pipe(babel())
.pipe(gulp.dest('lib'))
util.log(`File "${path}" rebuilt`)
})
.on('unlink', function(path) {
util.log(`File "${path}" removed`)
let filePathFromSrc = path.relative(path.resolve('src'))
let destFilePath = path.resolve('build', filePathFromSrc)
del.sync(destFilePath)
})
})
/**
* Entrypoint for running watch.
*/
gulp.task('build.watch', gulp.series('build', 'watch', function(done) {
done()
}))
gulp.task('default', gulp.series('clean', 'lint', 'build', function(done) {
done()
}))