-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (25 loc) · 886 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
const loaderUtils = require('loader-utils');
const utils = require('./utils');
const PugLoader = require('./lib/loader');
const getScript = (fileInfo) => {
// get scripts executed in webpack, which will replace path of all depedencies
let script = utils.requireAllResources(fileInfo.deps, 'requirePaths');
script += `
var tpl = ${JSON.stringify(fileInfo.content)};
for (var originPath in requirePaths) {
if (requirePaths.hasOwnProperty(originPath)) {
var rp = requirePaths[originPath];
while (tpl.indexOf(originPath) > -1) {
tpl = tpl.replace(originPath, rp);
}
}
}
module.exports = tpl;`;
return script;
};
module.exports = function () {
const options = loaderUtils.getOptions(this);
const loader = new PugLoader(this.resourcePath, options);
const fileInfo = loader.load();
return getScript(fileInfo);
};