-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathindex.js
39 lines (33 loc) · 907 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
'use strict';
const p = require('path');
const transform = require('buble').transform;
const relPath = obj => p.relative(obj.dir, p.format(obj));
module.exports = function (task) {
task.plugin('buble', {}, function * (file, opts) {
opts = Object.assign({
inline: false,
sourceMap: true,
file: file.base,
source: relPath(file)
}, opts);
// Transform data
const output = transform(file.data.toString(), opts);
// Handle sourcemaps
if (opts.sourceMap) {
if (opts.inline) {
// Append inline sourcemap
output.code += `\n//# sourceMappingURL=${output.map.toUrl()}`;
} else {
output.code += `\n//# sourceMappingURL=${opts.file}.map`;
// Create new file
this._.files.push({
base: `${opts.file}.map`,
data: output.map.toString(),
dir: file.dir
});
}
}
// doc: Return contents as Buffer!
file.data = new Buffer(output.code);
});
}