-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
35 lines (30 loc) · 998 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
/* eslint-disable no-invalid-this */
const buble = require('buble'),
path = require('path'),
loaderUtils = require('loader-utils');
class BubleError extends Error {
constructor(err) {
super();
Error.captureStackTrace(this, this.constructor);
this.name = 'BubleLoaderError';
this.message = ['', err.snippet, err.message].join('\n');
this.error = err;
}
}
module.exports = function(source) {
const config = loaderUtils.getOptions(this) || {};
config.transforms = Object.assign({}, config.transforms || {}, { modules: false });
let output;
try {
output = buble.transform(source, config);
}
catch (err) {
throw err.name === 'CompileError' || err.name === 'SyntaxError' ? new BubleError(err) : err;
}
const resourcePath = this.resourcePath;
output.map.file = resourcePath;
output.map.sources[0] = path.relative(process.cwd(), resourcePath);
output.map.sourceRoot = process.cwd();
if (this.cacheable) this.cacheable();
this.callback(null, output.code, output.map);
};