-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
rollup.config.mjs
138 lines (136 loc) · 4.79 KB
/
rollup.config.mjs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import alias from '@rollup/plugin-alias'
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import terser from '@rollup/plugin-terser'
import builtins from 'rollup-plugin-node-builtins'
import typescript from 'rollup-plugin-typescript2'
const outputs = [
{
input: `private_set_intersection/javascript/src/wasm_node.ts`,
onwarn(warning, warn) {
// suppress eval warnings from google-protobuf
if (warning.code === 'EVAL') return
warn(warning)
},
output: {
file: `private_set_intersection/javascript/dist/psi_wasm_node.js`,
sourcemap: true,
format: 'cjs',
name: 'PSI',
exports: 'auto',
plugins: [terser()]
},
plugins: [
// UGLY hack to 'fix' nodejs complaining about 'window' and 'self'
replace({
'return this || window || global || self ||':
'return this || global ||',
delimiters: ['', ''],
preventAssignment: true
}),
// Order of plugins matters!
// Depending on the format, we need to correctly transform the build for brower or nodejs
resolve({ preferBuiltins: true }), // needed to include the external google-protobuf module in the bundle
commonjs(), // needed to convert commonjs to es6 for protobuf
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
})
]
},
{
input: `private_set_intersection/javascript/src/wasm_web.ts`,
onwarn(warning, warn) {
// suppress eval warnings from google-protobuf
if (warning.code === 'EVAL') return
warn(warning)
},
output: {
file: `private_set_intersection/javascript/dist/psi_wasm_web.js`,
sourcemap: true,
format: 'umd',
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({ preferBuiltins: true }), // needed to include the external google-protobuf module in the bundle
commonjs(), // needed to convert commonjs to es6 for protobuf
builtins({ fs: true }),
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
})
]
},
{
input: `private_set_intersection/javascript/src/wasm_worker.ts`,
onwarn(warning, warn) {
// suppress eval warnings from google-protobuf
if (warning.code === 'EVAL') return
warn(warning)
},
output: {
file: `private_set_intersection/javascript/dist/psi_wasm_worker.js`,
sourcemap: true,
format: 'umd',
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({ preferBuiltins: true }), // needed to include the external google-protobuf module in the bundle
commonjs(), // needed to convert commonjs to es6 for protobuf
builtins({ fs: true }),
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
})
]
}
]
export default outputs