forked from olegstepura/typed-css-modules-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (26 loc) · 1.03 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
var path = require('path');
var DtsCreator = require('typed-css-modules');
var loaderUtils = require('loader-utils');
module.exports = function(source, map) {
this.cacheable && this.cacheable();
this.addDependency(this.resourcePath);
var callback = this.async();
// Pass on query parameters as an options object to the DtsCreator. This lets
// you change the default options of the DtsCreator and e.g. use a different
// output folder.
var queryOptions = loaderUtils.getOptions(this);
var options;
if (queryOptions) {
options = Object.assign({}, queryOptions);
}
var creator = new DtsCreator(options);
// creator.create(..., source) tells the module to operate on the
// source variable. Check API for more details.
creator.create(this.resourcePath, source).then(content => {
// Emit the created content as well
//this.emitFile(path.relative(this.options.context, content.outputFilePath), content.contents || [''], map);
content.writeFile().then(_ => {
callback(null, source, map);
});
});
};