-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (28 loc) · 870 Bytes
/
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
var through = require('through2');
var basename = require('path').basename;
var browserify = require('browserify');
function defaultName(path) {
return basename(path).split('.')[0];
}
module.exports = function (options) {
options = options || {};
options.ignoreMissing = true;
options.naming = options.naming || defaultName;
var b = browserify(options);
var depses = {};
var depsFiller = through.obj(function (row, enc, next) {
Object.keys(row.deps).forEach(function (key) {
if (row.deps[key] === undefined) {
row.deps[key] = depses[key];
}
});
var name = options.naming(row.file);
depses[name] = row.file;
next(null, row);
});
b.pipeline.get('deps').push(depsFiller);
b.on('reset', function () {
depses = {};
});
return b;
};