-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (34 loc) · 1.05 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
var bemdeclToFs = require('bemdecl-to-fs');
var loaderUtils = require('loader-utils');
var get = require('lodash.get');
var path = require('path');
/**
* query:
* - levels {string|string[]}
* - techs {string|string[]}
*
* @param {string|array} content
*/
module.exports = function (content) {
if (this.cacheable) {
this.cacheable();
}
var callback = this.async();
var query = loaderUtils.parseQuery(this.query);
var self = this;
var exts = query.extensions || get(this.options, 'bem.extensions');
var levels = query.levels || get(this.options, 'bem.levels');
var bemdecl = typeof content === 'string'
? this.exec(content, this.resourcePath)
: content; // assume that its a plain object / array
bemdeclToFs(bemdecl, levels, exts)
.then(function (files) {
var source = files.map(function (file) {
self.addDependency(file);
return 'require(' + loaderUtils.stringifyRequest(self, path.relative(self.context, file)) + ')';
})
.join('\n');
callback(null, source);
})
.catch(callback);
};