-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrollup.config.js
57 lines (51 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
47
48
49
50
51
52
53
54
55
56
57
import fs from "fs";
import path from "path";
import resolve from "@rollup/plugin-node-resolve";
import { base64 } from "rollup-plugin-base64";
import nodePolyfills from "rollup-plugin-node-polyfills";
import { terser } from "rollup-plugin-terser";
import typescript from "rollup-plugin-typescript2";
const packageJson = require("./package.json");
const globals = {
...packageJson.devDependencies,
};
export default {
input: "src/index.ts",
output: {
file: packageJson.module,
format: "esm",
},
plugins: [
typescript({
useTsconfigDeclarationDir: true,
}),
nodePolyfills(),
resolve({
browser: true,
preferBuiltins: false,
}),
// used to load in .wasm files as base64 strings, then can be instantiated with
// helper functions within `src/wasm.ts`.
base64({ include: "**/*.wasm" }),
{
// copy over rust-built declaration files to dist for later .d.ts bundling
name: "copy-pkg",
generateBundle() {
fs.mkdirSync(path.resolve(`dist/pkg`), { recursive: true });
["index.d.ts", "index_bg.wasm.d.ts"].forEach((file) => {
fs.copyFileSync(
path.resolve(`./pkg/${file}`),
path.resolve(`./dist/pkg/${file}`)
);
});
fs.copyFileSync(
path.resolve(`./pkg/index_bg.wasm`),
path.resolve(`./dist/index_bg.wasm`)
);
},
},
...(!process.env.ROLLUP_WATCH ? [terser()] : []),
],
external: [...Object.keys(globals)],
watch: { clearScreen: false },
};