-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
67 lines (62 loc) · 1.96 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
65
66
67
import commonjs from "@rollup/plugin-commonjs"
import typescript from "@rollup/plugin-typescript"
import { wasm } from "@rollup/plugin-wasm"
const production = !process.env.ROLLUP_WATCH
const outdir = (fmt, env) => {
if (env === "node") {
return `dist/node`
} else {
return `dist/${fmt}${env === "slim" ? "-slim" : ""}`
}
}
const rolls = (fmt, env) => ({
input: env !== "slim" ? "src/index.ts" : "src/index_slim.ts",
output: {
dir: outdir(fmt, env),
format: fmt,
entryFileNames: `[name].${fmt === "cjs" ? "cjs" : "js"}`,
name: "cloudproof_js",
globals: {
jose: "jose",
"base64-js": "base64-js",
uuid: "uuid",
cloudproof_kms_js: "cloudproof_kms_js",
},
},
external: ["jose", "uuid", "base64-js", "cloudproof_kms_js"],
plugins: [
commonjs(),
// We want to inline our wasm bundle as base64. Not needing browser users
// to fetch an additional asset is a boon as there's less room for errors
env !== "slim" &&
wasm(
env === "node"
? { maxFileSize: 0, targetEnv: "node" }
: { targetEnv: "auto-inline" },
),
typescript({
outDir: outdir(fmt, env),
rootDir: "src",
sourceMap: !production,
}),
{
name: "copy-pkg",
// wasm-bindgen outputs a import.meta.url when using the web target.
// rollup will either preserve the the statement when outputting an esm,
// which will cause webpack < 5 to choke or it will output a
// "require('url')", for other output types, causing more choking. Since
// we want a downstream developer to either not worry about providing wasm
// at all, or forcing them to deal with bundling, we resolve the import to
// an empty string. This will error at runtime.
resolveImportMeta: () => `""`,
},
],
})
export default [
rolls("umd", "fat"),
rolls("es", "fat"),
rolls("cjs", "fat"),
rolls("cjs", "node"),
// rolls("es", "slim"),
// rolls("cjs", "slim"),
]