-
Notifications
You must be signed in to change notification settings - Fork 759
/
gulpfile.babel.js
96 lines (87 loc) · 2.17 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import gulp from 'gulp';
import eslint from 'gulp-eslint';
import babel from 'gulp-babel';
import rename from 'gulp-rename';
import browserify from 'browserify';
import buffer from 'vinyl-buffer';
import del from 'del';
import source from 'vinyl-source-stream';
import sourcemaps from 'gulp-sourcemaps';
import uglify from 'gulp-uglify';
const ALL_SOURCES = [
'*.js',
'lib/*.js',
'test/*.js',
];
gulp.task('lint', function() {
return gulp.src(ALL_SOURCES)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
;
});
gulp.task('clean', function() {
return Promise.all([del('dist/'), del('coverage/')]);
});
gulp.task('build', [
'build:bundled:min',
'build:external:min',
'build:bundled:debug',
'build:external:debug',
'build:components',
]);
const bundledConfig = {
debug: true,
entries: 'lib/GitHub.js',
standalone: 'GitHub',
};
const externalConfig = {
debug: true,
entries: 'lib/GitHub.js',
standalone: 'GitHub',
external: [
'axios',
'js-base64',
'es6-promise',
'debug',
'utf8',
],
bundleExternal: false,
};
gulp.task('build:bundled:min', function() {
return buildBundle(bundledConfig, '.bundle.min.js', true);
});
gulp.task('build:external:min', function() {
return buildBundle(externalConfig, '.min.js', true);
});
gulp.task('build:bundled:debug', function() {
return buildBundle(bundledConfig, '.bundle.js', false);
});
gulp.task('build:external:debug', function() {
return buildBundle(externalConfig, '.js', false);
});
gulp.task('build:components', function() {
return gulp.src('lib/*.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/components'))
;
});
function buildBundle(options, extname, minify) {
let stream = browserify(options)
.transform('babelify')
.bundle()
.pipe(source('GitHub.js'))
.pipe(buffer())
.pipe(sourcemaps.init({
loadMaps: true,
}));
if (minify) {
stream = stream.pipe(uglify());
}
return stream.pipe(rename({extname}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'))
;
}