forked from coderespawn/dock-spawn
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
79 lines (67 loc) · 2.13 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
73
74
75
76
77
78
79
var gulp = require('gulp'),
gutil = require('gulp-util'),
jshint = require('gulp-jshint'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
watchify = require('watchify'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
browserify = require('browserify'),
rename = require("gulp-rename"),
path = require('path'),
index = './src/index.js',
outdir = './dist/js',
bundle = 'dockspawn',
outfile = 'dockspawn.js';
function rebundle(file) {
if (file) {
gutil.log('Rebundling,', path.basename(file[0]), 'has changes.');
}
return this.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source(outfile))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps:true, debug:true})) // init source map
.pipe(gulp.dest(outdir)) //generate the non-minified
.pipe(rename({extname:'.min.js'}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(outdir));
}
function createBundler(args) {
args = args || {};
args.standalone = bundle;
args.debug = true;//let browserify generate sourcemap. (will be inlined, loaded in sourcemaps, then removed by uglify, and finally generated in .map by sourcemaps)
return browserify(index, args);
}
/*****
* Dev task, incrementally rebuilds the output bundle as the the sources change
*****/
gulp.task('dev', function() {
watchify.args.standalone = bundle;
var bundler = watchify(createBundler(watchify.args));
bundler.on('update', rebundle);
return rebundle.call(bundler);
});
/*****
* Build task, builds the output bundle
*****/
gulp.task('build', function () {
return rebundle.call(createBundler());
});
/*****
* JSHint task, lints the lib and test *.js files.
*****/
gulp.task('jshint', function () {
return gulp.src([
'./src/**/*.js',
'gulpfile.js'
])
.pipe(jshint())
.pipe(jshint.reporter('jshint-summary'));
});
/*****
* Base task
*****/
gulp.task('default', ['jshint', 'build']);