-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
26 lines (20 loc) · 791 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
'use strict';
const _ = require('lodash');
const loaderUtils = require('loader-utils');
module.exports = function (source) {
const options = loaderUtils.getOptions(this) || {};
_.templateSettings.imports = _.isObject(options.imports) ? options.imports : {};
_.templateSettings.imports._ = _;
if (_.isRegExp(options.escape)) {
_.templateSettings.escape = options.escape;
}
if (_.isRegExp(options.evaluate)) {
_.templateSettings.evaluate = options.evaluate;
}
if (_.isRegExp(options.interpolate)) {
_.templateSettings.interpolate = options.interpolate;
}
const compiled = _.template(source);
const renderedView = compiled();
return 'module.exports = function() { return ' + JSON.stringify(renderedView) + '; };';
};