-
Notifications
You must be signed in to change notification settings - Fork 19
/
rollup.config.js
58 lines (54 loc) · 1.23 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
47
48
49
50
51
52
53
54
55
56
57
58
import { readFile, writeFile } from "fs/promises";
const globals = {
__proto__: null,
tslib: "tslib",
assert: "assert",
crypto: "crypto",
"@wry/equality": "wryEquality",
"@wry/context": "wryContext",
"@wry/trie": "wryTrie",
"@wry/caches": "wryCaches",
};
function external(id) {
return id in globals;
}
function build(input, output, format) {
return {
input,
external,
output: {
file: output,
format,
sourcemap: true,
globals
},
...(output.endsWith(".cjs") ? { plugins: [
{ // Inspired by https://github.com/apollographql/apollo-client/pull/9716,
// this workaround ensures compatibility with versions of React Native
// that refuse to load .cjs modules as CommonJS (to be fixed in v0.72):
name: "copy *.cjs to *.cjs.native.js",
async writeBundle({ file }) {
const buffer = await readFile(file);
await writeFile(file + ".native.js", buffer);
},
},
]} : null),
};
}
export default [
build(
"lib/es5/index.js",
"lib/bundle.cjs",
"cjs"
),
build(
"lib/tests/main.js",
"lib/tests/bundle.js",
"esm"
),
build(
"lib/es5/tests/main.js",
"lib/tests/bundle.cjs",
"cjs"
),
];