-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.js
31 lines (25 loc) · 919 Bytes
/
loader.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
const qs = require('querystring');
const loaderUtils = require('loader-utils');
module.exports = function (source) {
const loaderContext = this;
const {resourceQuery} = loaderContext;
const rawQuery = resourceQuery.slice(1);
const incomingQuery = qs.parse(rawQuery);
const options = loaderUtils.getOptions(loaderContext) || {};
/**
* Don't handle x-template
*/
if (options.type === 'x-template') {
return '';
}
/**
* Convert x-style and x-script tag to style and script tag
*/
source = source.replace(/<x-style/g, '<style');
source = source.replace(/<style/g, '<style xbType="style"');
source = source.replace(/<\/x-style/g, '</style');
source = source.replace(/<x-script/g, '<script');
source = source.replace(/<script/g, '<script xbType="script"');
source = source.replace(/<\/x-script/g, '</script');
return source;
}