-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
59 lines (50 loc) · 1.52 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
import gulp from 'gulp'
import sourcemaps from 'gulp-sourcemaps'
import source from 'vinyl-source-stream'
import buffer from 'vinyl-buffer'
import browserify from 'browserify'
import watchify from 'watchify'
import babel from 'babelify'
import uglifyify from 'uglifyify'
import mocha from 'gulp-mocha'
const src = {
js: './index.js'
}
const debug = (process.env.NODE_ENV || 'debug').toLowerCase() == 'debug'
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: debug })
.transform(babel)
.transform(uglifyify));
function rebundle() {
bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(source('build.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build'));
}
if (watch) {
bundler.on('update', function() {
console.log('-> bundling...');
rebundle();
});
}
rebundle();
}
function watch() {
return compile(true);
};
gulp.task('build', function() { return compile(); });
gulp.task('watch', function() { return watch(); });
gulp.task('default', ['watch']);
/**
* Run test once and exit
*/
gulp.task('test', function (done) {
return gulp.src('test/**/*.js', {read: false})
.pipe(mocha({
require: [__dirname + '/src-dev/jsdom.js'],
reporter: 'nyan',
}));
});