forked from yarnpkg/berry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
46 lines (42 loc) Β· 1.51 KB
/
rollup.config.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
import cjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import path from 'path';
import esbuild from 'rollup-plugin-esbuild';
import {brotliCompressSync} from 'zlib';
function wrapOutput() {
return {
name: `wrap-output`,
generateBundle(options, bundle, isWrite) {
const bundles = Object.keys(bundle);
if (bundles.length !== 1)
throw new Error(`Expected only one bundle, got ${bundles.length}`);
const outputBundle = bundle[bundles[0]];
outputBundle.code = `let hook;\n\nmodule.exports.getContent = () => {\n if (typeof hook === \`undefined\`)\n hook = require('zlib').brotliDecompressSync(Buffer.from('${brotliCompressSync(
outputBundle.code.replace(/\r\n/g, `\n`)
).toString(`base64`)}', 'base64')).toString();\n\n return hook;\n};\n`;
},
};
}
// eslint-disable-next-line arca/no-default-export
export default [
{
input: `./sources/worker-zip/Worker.ts`,
output: {
file: `./sources/worker-zip/index.js`,
format: `cjs`,
strict: false,
preferConst: true,
},
plugins: [
resolve({
extensions: [`.mjs`, `.js`, `.ts`, `.tsx`, `.json`],
rootDir: path.join(__dirname, `../../`),
jail: path.join(__dirname, `../../`),
preferBuiltins: true,
}),
esbuild({tsconfig: false, target: `es2018`}),
cjs({transformMixedEsModules: true, extensions: [`.js`, `.ts`]}),
wrapOutput(),
],
},
];