-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
45 lines (40 loc) · 1.19 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
'use strict';
import { rollup } from 'rollup';
export class RollupCompiler {
constructor(config) {
if (config == null) config = {};
var pluginConfig = config.plugins && config.plugins.rollup || {};
this.config = pluginConfig;
this.extension = pluginConfig.extension || 'js';
this.plugins = pluginConfig.plugins || [];
delete pluginConfig.extension;
}
compile(params) {
const path = params.path;
const data = params.data;
const config = this.config;
const plugins = this.plugins.slice();
plugins.unshift({
name: 'rollup-plugin-brunch',
resolveId() { return path; },
load() { return { code: data }; }
});
return rollup({
input: path,
plugins: plugins
}).then(bundle => bundle.generate({
format: config.format || 'umd',
name: path,
sourcemap: config.sourcemap ? 'hidden' : false
})).then(({ output }) => {
const compiled = output[0];
return {
data: compiled.code,
map: compiled.map ? compiled.map.toString() : null
};
});
}
}
RollupCompiler.prototype.brunchPlugin = true;
RollupCompiler.prototype.type = 'javascript';
RollupCompiler.prototype.extension = 'js';