-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
73 lines (63 loc) · 1.62 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
require('babel-core/register');
var gulp = require('gulp');
var babelify = require('babelify');
var browserify = require('browserify');
var babel = require('gulp-babel');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
var del = require('del');
var mocha = require('gulp-mocha');
import sourcemaps from 'gulp-sourcemaps';
function buildScript(scriptName) {
let path = './src/' + scriptName;
let b = browserify(path, {
// cache: {},
// packageCache: {},
standalone: 'dataloaders',
debug: true
});
b = b.transform(babelify, {
presets: ['es2015']
});
return b.bundle()
.pipe(source(scriptName))
.on('error', function (err) { console.error(err); })
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('dist'))
}
function buildScripts(scripts) {
for (var s=0; s<scripts.length; s++) {
var script = scripts[s];
buildScript(script);
}
}
function copyUtils() {
gulp.src('src/utils/*.js', {
base: 'src'
}).pipe(gulp.dest('dist'));
}
gulp.task('clearDist', function(){
del('dist', {dot: true});
del('dist/utils/*');
})
gulp.task('default', ['clearDist'], function(){
copyUtils();
var scripts = ['dataloaders.js', 'sw-dataloaders.js'];
buildScripts(scripts);
});
gulp.task('test', function() {
// return gulp.src(['test/*.js'])
// .pipe(mocha({
// compilers:babelregister
// }));
return gulp.src('test/*.test.js', { read: false })
.pipe(mocha({
reporter: 'nyan',
compilers:'js:babel-core/register'
}));
});