-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
41 lines (39 loc) · 903 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
36
37
38
39
40
41
const utils = require('loader-utils');
const discover = require('./lib/discover');
const serialize = require('./lib/serialize');
function generateLoader() {
let options = utils.getOptions(this);
if (!options) {
options = {};
}
if (!options.debug) {
options.debug = false;
}
if (!options.graph) {
options.graph = null;
}
if (!options.baseDir) {
options.baseDir = process.cwd();
}
if (!options.manifest) {
options.manifest = {
runtimes: ['noflo'],
discover: true,
recursive: true,
};
}
if (!options.runtimes) {
options.runtimes = options.manifest.runtimes;
}
this.cacheable();
const callback = this.async();
discover(options)
.then((modules) => serialize(modules, options))
.then((loader) => {
callback(null, loader);
})
.catch((err) => {
callback(err);
});
}
module.exports = generateLoader;