forked from enmasseio/evejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (62 loc) · 1.79 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 fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var webpack = require('webpack');
var uglify = require('uglify-js');
var ENTRY = './index.js';
var FILE = 'eve.js';
var FILE_MIN = 'eve.min.js';
var FILE_MAP = 'eve.map';
var DIST = './dist';
var EVE_JS = DIST + '/' + FILE;
var EVE_MIN_JS = DIST + '/' + FILE_MIN;
var EVE_MAP_JS = DIST + '/' + FILE_MAP;
var webpackConfig = {
entry: ENTRY,
output: {
library: 'eve',
libraryTarget: 'umd',
path: DIST,
filename: FILE
},
externals: [
// TODO: exclude all non-relevant libraries from the browser bundle
'amqp'
],
cache: true
};
var uglifyConfig = {
outSourceMap: FILE_MAP,
output: {
comments: /@license/
}
};
// create a single instance of the compiler to allow caching
var compiler = webpack(webpackConfig);
gulp.task('bundle', function (cb) {
// TODO: add a header (banner) on top of the file
compiler.run(function (err, stats) {
if (err) {
gutil.log(err);
}
gutil.log('bundled ' + EVE_JS);
cb();
});
});
gulp.task('minify', ['bundle'], function () {
var result = uglify.minify([EVE_JS], uglifyConfig);
fs.writeFileSync(EVE_MIN_JS, result.code);
fs.writeFileSync(EVE_MAP_JS, result.map);
gutil.log('Minified ' + EVE_MIN_JS);
gutil.log('Mapped ' + EVE_MAP_JS);
});
// The default task (called when you run `gulp`)
gulp.task('default', ['bundle', 'minify']);
// Watch task to automatically bundle and minify on change of code
gulp.task('watch', ['bundle', 'minify'], function () {
gulp.watch(['index.js', 'lib/**/*.js'], ['bundle', 'minify']);
});
// Watch task to automatically bundle on change of code
gulp.task('watch-bundle', ['bundle'], function () {
gulp.watch(['index.js', 'lib/**/*.js'], ['bundle']);
});