-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 957 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
33
34
35
36
37
38
39
/**
* Created by glenn on 01.06.16.
* Last updated on 14.10.18.
*/
// const { getOptions } = require('loader-utils');
// const validateOptions = require('schema-utils');
//
// const schema = {
// type: 'object',
// properties: {
// test: {
// type: 'string'
// }
// }
// };
const falafel = require('falafel');
module.exports = function hodorLoader(source) {
// const options = getOptions(this);
// console.log(options);
// validateOptions(schema, options, 'Hodor Loader');
// Apply some transformations to the source...
// console.log(source);
const transformed = falafel({ source }, node => {
if (node.type === 'Literal' && typeof node.value === 'string') {
node.update(node.source().replace(/\w+/g, 'HODOR'));
}
if (node.type === 'TemplateLiteral') {
node.update(node.source().replace(/\w+|\${.+}/g, 'HODOR'));
}
});
// console.log(transformed);
return transformed.toString();
};