-
Notifications
You must be signed in to change notification settings - Fork 16
/
Gulpfile.js
83 lines (72 loc) · 1.9 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
var gulp = require('gulp');
var _ = require('gulp-load-plugins')();
gulp.task('default', ['test']);
gulp.task('test', function(cb) {
var spawn = require('child_process').spawn;
var child = spawn('npm', ['test'], {stdio: 'inherit'});
child.on('exit', function(code) {
cb(code ? new Error('Tests Failed') : null);
});
});
gulp.task('build', ['browser', 'vm']);
gulp.task('browser', function() {
var vars = [], varsMap = {};
var replacePrivate = function(name) {
var map = varsMap[name];
if (!map) {
vars.push(name);
map = '._' + vars.length.toString(32);
varsMap[name] = map;
// console.log(vars.length, map, name);
}
return map;
};
gulp.src('lib/slm_browser.js')
.pipe(_.webpack({
output: {
filename: 'slm-browser.js',
library: 'Slm',
libraryTarget: 'umd'
}
}))
.pipe(_.size({showFiles: true}))
.pipe(gulp.dest('dist'))
.pipe(_.replace( /\._(\w+)/g, replacePrivate))
.pipe(_.uglify())
.pipe(_.concat('slm-browser.min.js'))
.pipe(_.size({showFiles: true}))
.pipe(gulp.dest('dist'))
.pipe(_.gzip())
.pipe(_.size({showFiles: true}))
.pipe(gulp.dest('dist'));
});
gulp.task('vm', function() {
var vars = [];
var varsMap = {};
var replacePrivate = function(name) {
var map = varsMap[name];
if (!map) {
vars.push(name);
map = varsMap[name] = '._' + vars.length.toString(32);
}
return map;
};
gulp.src('lib/vm_browser.js')
.pipe(_.webpack({
output: {
filename: 'slm-vm-browser.js',
library: 'SlmVM',
libraryTarget: 'umd'
}
}))
.pipe(_.size({showFiles: true}))
.pipe(gulp.dest('dist'))
.pipe(_.replace( /\._(\w+)/g, replacePrivate))
.pipe(_.uglify())
.pipe(_.concat('slm-vm-browser.min.js'))
.pipe(_.size({showFiles: true}))
.pipe(gulp.dest('dist'))
.pipe(_.gzip())
.pipe(_.size({showFiles: true}))
.pipe(gulp.dest('dist'));
});