forked from sjkummer/janus-gateway-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (65 loc) · 1.66 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
var gulp = require('gulp');
var rename = require("gulp-rename");
var browserify = require('browserify');
var nodeResolve = require('resolve');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var log = require('fancy-log');
var exorcist = require('exorcist');
var browserifyTask = function() {
var b = browserify({
entries: './src/index.js',
standalone: 'Janus',
debug: true
});
return b.bundle()
.pipe(exorcist('./dist/janus.js.map'))
.pipe(source('janus.js'))
.pipe(gulp.dest('./dist'))
.pipe(rename('janus.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.on('error', log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
};
var vendorTask = function(external) {
var b = browserify();
if (external) {
external.forEach(function(id) {
b.require(nodeResolve.sync(id), {expose: id});
});
var stream = b
.bundle()
.on('error', function(err) {
console.log(err.message);
this.emit('end');
})
.pipe(source('vendor.js'));
stream
.pipe(gulp.dest('./dist'))
.pipe(rename('vendor.min.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./dist'));
return stream;
}
};
function build(cb) {
browserifyTask();
cb();
}
function external(cb) {
vendorTask(['bluebird', 'webrtc-adapter']);
browserifyTask();
cb();
}
exports.build = build;
exports.external = external;
/*
* Define default task that can be called by just running `gulp` from cli
*/
exports.default = build;