-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
72 lines (60 loc) · 1.92 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
70
71
72
'use strict';
var babelify = require('babelify');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var uglify = require('gulp-uglify');
var filelog = require('gulp-filelog');
var header = require('gulp-header');
var sourcemaps = require('gulp-sourcemaps');
var through = require('through2');
var parseArgs = require('minimist');
var fs = require('fs');
var path = require('path');
var PKG_INFO = require('./package.json');
// gulp-header.
var BANNER = fs.readFileSync('banner.txt').toString();
var BANNER_OPTS = {
pkg: PKG_INFO,
currentYear: (new Date()).getFullYear()
};
var noop = function() {
return through.obj();
}
var env = parseArgs(process.argv.slice(2));
gulp.task('lint', function () {
return gulp.src('lib/**/*.js')
.pipe(filelog('lint'))
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter(stylish));
});
gulp.task('build', function () {
var dest;
var isProduction = (env.type === 'production');
if (isProduction) {
dest = PKG_INFO.name + '.min.js';
} else {
dest = PKG_INFO.name + '.js';
}
return browserify([path.join(__dirname, PKG_INFO.main)],
{standalone: PKG_INFO.name,
debug: true})
.transform(babelify)
.bundle()
.pipe(source(dest))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(filelog('build'))
.pipe(isProduction ? uglify({mangle: false}) : noop())
.pipe(header(BANNER, BANNER_OPTS))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/'));
});
gulp.task('watch', function() {
gulp.watch(['lib/**/*.js'], gulp.series('lint', 'build'));
});
gulp.task('dist', gulp.series('lint', 'build'));
gulp.task('default', gulp.series('dist'));