-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.babel.js
68 lines (58 loc) · 1.87 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
'use strict';
import gulp from 'gulp';
import rename from 'gulp-rename';
import bump from 'gulp-bump';
import gutil from 'gulp-util';
import uglify from 'gulp-uglify';
import sourcemaps from 'gulp-sourcemaps';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import browserify from 'browserify';
import babelify from 'babelify';
import del from 'del';
import path from 'path';
let src = './src.js';
let minext = '.min';
let pack = require('./package.json');
// clean up
function clean(done) {
let d = path.dirname(pack.main);
let e = path.extname(pack.main);
let b = path.basename(pack.main);
let n = b.replace(e, '');
let mapf = path.join(d, b + '.map');
let minf = path.join(d, n + minext + e);
del([pack.main, mapf, minf, '*.log'], done);
}
// umd standalone library with sourcemaps
function umd() {
let bundler = browserify(src, { debug: true, standalone: 'luhn' })
.transform(babelify) // .configure({ optional: ['runtime'] })
.bundle();
return bundler
.pipe(source(pack.main)) // gives streaming vinyl file object
.pipe(buffer()) // convert from streaming to buffered vinyl file object
.pipe(sourcemaps.init({ loadMaps: true })) // loads map from browserify file
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./'));
}
// minified umd standalone library
function min() {
return gulp.src(pack.main)
.pipe(uglify())
.on('error', gutil.log)
.pipe(rename({ extname: minext + '.js' }))
.pipe(gulp.dest('./'));
}
function bumpall() {
return gulp.src(['./package.json', './bower.json'])
.pipe(bump({ type: 'patch' }))
.pipe(gulp.dest('./'));
}
let development = gulp.series(clean, umd);
let production = gulp.series(development, min);
gulp.task('bump', bumpall);
gulp.task('clean', clean);
gulp.task('development', development);
gulp.task('production', production);
gulp.task('default', production);