forked from vispy/vispy.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
85 lines (71 loc) · 2.27 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
80
81
82
83
84
85
var gulp = require('gulp'),
gutil = require('gulp-util'),
jshint = require('gulp-jshint'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
watchify = require('watchify'),
browserify = require('browserify'),
sourcemaps = require('gulp-sourcemaps'),
path = require('path'),
uglify = require('gulp-uglify'),
rename = require("gulp-rename"),
index = './scripts/vispy.js',
outdir = './dist/',
bundle = 'vispy',
outfile = 'vispy.js';
var srcs = [
'./scripts/**/*.js',
'gulpfile.js'
];
function rebundle(file) {
if (file) {
gutil.log('Rebundling,', path.basename(file[0]), 'has changes.');
}
return this.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error')) // log errors if they happen
.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(srcs)
.pipe(jshint())
.pipe(jshint.reporter('jshint-summary'));
});
// gulp.task('compress', ['build'], function() {
// gulp.src(outdir + outfile)
// .pipe(gulp.dest(outdir))
// });
/*****
* Base task
*****/
gulp.task('default', ['jshint', 'build']);