-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
23 lines (17 loc) · 729 Bytes
/
Copy pathindex.js
File metadata and controls
23 lines (17 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const Mustache = require('mustache');
const loaderUtils = require('loader-utils');
module.exports = function (source) {
const options = loaderUtils.getOptions(this) || {};
let viewData = {};
if (options.viewData) {
viewData = options.viewData;
}
if (options.delimiters) {
if (!Array.isArray(options.delimiters) || options.delimiters.length !== 2) {
throw new Error('Custom delimiters option must be an array consisting of the opening and closing tag values.');
}
Mustache.tags = options.delimiters;
}
const renderedView = Mustache.render(source, viewData);
return 'module.exports = function() { return ' + JSON.stringify(renderedView) + '; };';
};