forked from istr/rollup-brunch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
52 lines (48 loc) · 1.47 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
const rollup = require('rollup');
const memory = require('rollup-plugin-memory');
const pathResolve = require('path').resolve;
class RollupCompiler {
constructor(config) {
if (config == null) config = {};
var pluginConfig = config.plugins && config.plugins.rollup || {};
if (pluginConfig.entry) {
this.pattern = new RegExp(pluginConfig.entry);
}
this.config = pluginConfig;
this.extension = pluginConfig.extension || 'js';
delete pluginConfig.extension;
}
compile(params) {
const path = pathResolve(params.path); // this fixes an issue where using rollup plugins like typescript filters out the file
const data = params.data;
const config = this.config;
const plugins = (config.plugins || []).slice();
plugins.push(memory({
contents: data
}));
return rollup.rollup({
entry: path,
plugins: plugins
}).then((bundle) => {
const compiled = bundle.generate({
format: config.format || 'umd',
moduleName: config.moduleName,
sourceMap: config.sourceMap || 'none'
});
var code;
if (this.map === 'linked') {
code = compiled.code.replace('//# sourceMappingURL=undefined.map\n', '');
} else {
code = compiled.code;
}
return {
data: code,
map: compiled.map.toString()
};
});
}
}
RollupCompiler.prototype.brunchPlugin = true;
RollupCompiler.prototype.type = 'javascript';
module.exports = RollupCompiler;