forked from lyaunzbe/ptolemy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
68 lines (55 loc) · 1.6 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
'use strict';
const Gulp = require('gulp');
const Rename = require('gulp-rename');
const Source = require('vinyl-source-stream');
const Browserify = require('browserify');
const Derequire = require('gulp-derequire');
const Watchify = require('watchify');
const Babelify = require('babelify');
const Notify = require('gulp-notify');
function compile (watch) {
let bundler = Browserify({
// Required watchify args
cache: {}, packageCache: {},
// Specify the entry point of your app
entries: ['./lib/ptolemy.js'],
// Enable source maps!
debug: true,
// Allows this to be included from as bundled library
standalone: 'window'
});
bundler
.transform(Babelify.configure({
presets: ['latest']
}))
.transform('debowerify');
let bundle = function () {
console.log('Bundling ->');
return bundler.bundle()
.on('error', function() {
let args = Array.prototype.slice.call(arguments);
// Send error to notification center with gulp-notify
Notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, args);
// Keep gulp from hanging on this task
this.emit('end');
})
.pipe(Source('./index.js'))
.pipe(Derequire())
.pipe(Rename('ptolemy.js'))
.pipe(Gulp.dest('dist/'))
};
if (watch) {
bundler = Watchify(bundler)
.on('update', bundle);
return bundle();
}
return bundle();
}
function watch() {
return compile(true);
};
Gulp.task('build', function () { return compile(); });
Gulp.task('watch', function() { return watch(); });