-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
32 lines (24 loc) · 995 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
'use strict';
var loaderUtils = require("loader-utils");
var slm = require("slm");
var markdown = require("slm-markdown");
markdown.register(slm.template);
module.exports = function(source) {
this.cacheable && this.cacheable(true);
var options = loaderUtils.getOptions(this) || {};
options.filename = this.resourcePath;
var tmplFunc = slm.compile(source, options);
// watch for changes in every referenced file
Object.keys(slm.template.VM.prototype._cache).forEach(function(dep) {
this.addDependency(dep);
}, this);
// slm cache used to remember paths to all referenced files
// purge cache after each run to force rebuild on changes
// each cached chunk is deleted from original object,
// cause it's referenced by slm internally in other places
// replacing cache with new object {} will break hot reload
Object.keys(slm.template.VM.prototype._cache).forEach(function(dep) {
delete slm.template.VM.prototype._cache[dep];
});
return tmplFunc();
};