-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.js
More file actions
32 lines (27 loc) · 912 Bytes
/
loader.js
File metadata and controls
32 lines (27 loc) · 912 Bytes
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
const transform = require('./transform');
const compiler = require('@vue/compiler-sfc');
function pad(source) {
return source.split(/\r?\n/).map(line => ` ${line}`).join('\n');
}
module.exports = function (content) {
const callback = this.async();
transform(content, this.resourcePath).then(({code, map, tips, errors, template}) => {
for (const tip of tips || []) {
this.emitWarning(typeof tip === 'object' ? tip.msg : tip);
}
if (errors && errors.length) {
this.emitError(
'\n\n Errors compiling template:\n\n' +
errors.map(({msg, start, end}) => {
if (template.content) {
const frame = compiler.generateCodeFrame(template.content, start, end)
if (frame) return ` ${msg}\n\n${pad(frame)}`
}
return ` ${msg}`
}).join('\n\n') +
'\n'
);
}
callback(null, code, map);
});
};