-
Notifications
You must be signed in to change notification settings - Fork 21
/
rollup.config.js
64 lines (58 loc) · 1.47 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
59
60
61
62
63
64
import { readFileSync } from "fs";
import { dirname, resolve } from "path";
import copy from "rollup-plugin-copy";
import nodeResolve from "rollup-plugin-node-resolve";
import replace from "rollup-plugin-replace";
import { swc } from "rollup-plugin-swc3";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const wasmBytes = Array.from(
readFileSync(resolve(__dirname, "src/xxhash.wasm")),
);
const output = [
{
file: "cjs/xxhash-wasm.cjs",
format: "cjs",
sourcemap: true,
exports: "default",
},
{ file: "esm/xxhash-wasm.js", format: "es", sourcemap: true },
{
file: "umd/xxhash-wasm.js",
format: "umd",
name: "xxhash",
sourcemap: true,
},
];
const replacements = {
WASM_PRECOMPILED_BYTES: JSON.stringify(wasmBytes),
};
const swc_config = JSON.parse(
readFileSync(resolve(__dirname, ".swcrc"), "utf-8"),
);
const plugins = [
replace(replacements),
// The config is necessary, because the plugin overwrites some of the settings,
// instead of just falling back to .swcrc
swc(swc_config),
nodeResolve(),
];
export default [
{
input: "src/index.js",
output,
plugins,
},
{
input: "src/index.workerd.js",
output: { file: "workerd/xxhash-wasm.js", format: "es", sourcemap: true },
external: /\.wasm$/,
plugins: [
...plugins,
copy({
targets: [{ src: "src/xxhash.wasm", dest: "workerd" }],
}),
],
},
];