UNPKG

956 BJavaScriptView Raw
1'use strict';
2
3var stream$1 = require('stream');
4var rollup = require('rollup');
5
6const build = async (options, stream) => {
7 const bundle = await rollup.rollup(options);
8 stream.emit('bundle', bundle);
9 const { output } = await bundle.generate(options);
10 for (const chunk of output) {
11 if (chunk.type === 'asset') {
12 stream.push(chunk.source);
13 }
14 else {
15 stream.push(chunk.code);
16 if (chunk.map) {
17 stream.push(`\n//# sourceMappingURL=${chunk.map.toUrl()}`);
18 }
19 }
20 }
21 // signal end of write
22 stream.push(null);
23};
24const stream = (options) => {
25 const result = new stream$1.Readable({
26 // stub _read() as it's not available on Readable stream, needed by gulp et al
27 read: () => { }
28 });
29 build(options, result).catch((error) => {
30 result.emit('error', error);
31 });
32 return result;
33};
34
35module.exports = stream;