-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
rollup.config.js
82 lines (81 loc) · 3.11 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { terser } from 'rollup-plugin-terser'
import alias from '@rollup/plugin-alias'
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import globals from 'rollup-plugin-node-globals'
import builtins from 'rollup-plugin-node-builtins'
import typescript from 'rollup-plugin-typescript2'
const formats = ['umd']
const targets = ['client', 'server', 'combined']
const variants = ['wasm', 'js']
const environments = ['node', 'web', 'worker']
const outputs = formats.reduce(
(acc, format) => [
...acc,
...targets.reduce(
(acc, target) => [
...acc,
...variants.reduce(
(acc, variant) => [
...acc,
...environments.reduce(
(acc, environment) => [
...acc,
{
input: `private_set_intersection/javascript/src/${target}_${variant}_${environment}.ts`,
onwarn(warning, warn) {
// suppress eval warnings from google-protobuf
if (warning.code === 'EVAL') return
warn(warning)
},
output: {
file: `private_set_intersection/javascript/dist/${target}_${variant}_${environment}.js`,
sourcemap: true,
format,
name: 'PSI',
exports: 'auto',
plugins: [terser()]
},
plugins: [
// Order of plugins matters!
// Depending on the format, we need to correctly transform the build for brower or nodejs
resolve(), // needed to include the external google-protobuf module in the bundle
commonjs(), // needed to convert commonjs to es6 for protobuf
format !== 'cjs'
? globals({ global: true, buffer: true })
: undefined,
format !== 'cjs' ? builtins({ fs: true }) : undefined,
alias({
entries: [
// Used to replace the paths that use `import * psi from './psi_*'` statement to point to their respective JS files
{
find: /^psi_(.*)$/,
replacement:
'./private_set_intersection/javascript/bin/psi_$1.js'
},
// Used to replace the `import { ServerSetup, Request, Response } from './proto/psi_pb'` statement to point to the JS file
{
find: /^\.\/proto\/psi_(.*)$/,
replacement:
'./private_set_intersection/javascript/bin/psi_$1.js'
}
]
}),
typescript({
verbosity: 2
})
].filter(Boolean)
}
],
[]
)
],
[]
)
],
[]
)
],
[]
)
export default outputs