-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
35 lines (25 loc) · 923 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
const path = require('path');
const dust = require('dustjs-linkedin');
const loaderUtils = require('loader-utils')
module.exports = function(content) {
const options = loaderUtils.getOptions(this) || {};
//If rootDir is configured then omit it from the template name
const rootDir = options['rootDir'] ? `${path.normalize(options['rootDir'])}${path.sep}` : '';
if (this.cacheable) {
this.cacheable();
}
if (typeof options === "string" && options.indexOf('preserveWhitespace') > -1) {
dust.config.whitespace = true;
}
if (options['preserveWhitespace']) {
dust.config.whitespace = true;
}
const context = this.rootContext || this.options.context;
const name = this.resourcePath
.replace(context + path.sep + rootDir, '')
.replace('.dust', '')
.split(path.sep)
.join('/');
const compiled = dust.compile(content, name);
return "module.exports = " + compiled;
};