1 | import { Readable } from 'stream';
|
2 | import { rollup } from 'rollup';
|
3 |
|
4 | const build = async (options, stream) => {
|
5 | const bundle = await rollup(options);
|
6 | stream.emit('bundle', bundle);
|
7 | const { output } = await bundle.generate(options);
|
8 | for (const chunk of output) {
|
9 | if (chunk.type === 'asset') {
|
10 | stream.push(chunk.source);
|
11 | }
|
12 | else {
|
13 | stream.push(chunk.code);
|
14 | if (chunk.map) {
|
15 | stream.push(`\n//# sourceMappingURL=${chunk.map.toUrl()}`);
|
16 | }
|
17 | }
|
18 | }
|
19 |
|
20 | stream.push(null);
|
21 | };
|
22 | const stream = (options) => {
|
23 | const result = new Readable({
|
24 |
|
25 | read: () => { }
|
26 | });
|
27 | build(options, result).catch((error) => {
|
28 | result.emit('error', error);
|
29 | });
|
30 | return result;
|
31 | };
|
32 |
|
33 | export default stream;
|