-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlwc-loader.js
More file actions
27 lines (24 loc) · 834 Bytes
/
lwc-loader.js
File metadata and controls
27 lines (24 loc) · 834 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
const { transform } = require('@lwc/compiler');
const path = require('path');
module.exports = function lwcLoader(source) {
const { resourcePath } = this;
const ext = path.extname(resourcePath);
const basename = path.basename(resourcePath, ext);
const extMap = {
...this.query.extMap,
'.js': '.js',
'.css': '.css',
'.html': '.html',
};
const mappedExt = extMap[ext];
if (mappedExt === undefined) {
throw new Error(`[lwc-loader] Cannot transform file with extension "${ext}". Please map "${ext}" to ".js", ".html" or ".css" in options.extMap`);
}
return transform(source, path.basename(resourcePath).replace(ext, mappedExt), {
namespace: this.query.namespace,
name: basename
})
.then((data) => {
return data.code;
});
}