-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (40 loc) · 1.16 KB
/
index.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
module.exports = function (options, imports, register) {
var middleware = require('./middleware');
var browserify = require('browserify');
var uglifyjs = require("uglify-js"),
parser = uglifyjs.parser,
uglify = uglifyjs.uglify;
options.imports = options.imports || [];
var compile = function (path) {
var bundle = browserify({
entry: path,
debug: !!options.debug,
filter: function(code) {
if(!!options.compress) {
var ast = parser.parse(code);
ast = uglify.ast_mangle(ast);
ast = uglify.ast_squeeze(ast);
return uglify.gen_code(ast);
}
else {
return code;
}
}
});
if (options.imports) {
for (var i = options.imports.length - 1; i >= 0; i--) {
var importPath = options.imports[i]
bundle.require(importPath);
};
}
imports.logger.debug('Javascript compiled at '+path);
return bundle;
};
imports.express.use(middleware({
src: options.src,
dest: options.dest,
compile: compile
}));
imports.logger.debug('browserify ready to compile');
register(null, {});
};