-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
120 lines (110 loc) · 3.16 KB
/
Copy pathrollup.config.js
File metadata and controls
120 lines (110 loc) · 3.16 KB
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
import { createRequire } from 'module';
import commonjs from '@rollup/plugin-commonjs';
import inject from '@rollup/plugin-inject';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import dts from 'rollup-plugin-dts';
import esbuild from 'rollup-plugin-esbuild';
import nodePolyfills from 'rollup-plugin-polyfill-node';
const require = createRequire(import.meta.url);
const pkg = require('./package.json');
/**
* We must NOT mark circomlibjs/blake-hash as external, otherwise the SDK build cannot patch them.
* Buffer must be bundled too, so injected imports work without UI config.
*/
const FORCE_BUNDLE_DEPS = new Set(['buffer', 'circomlibjs', 'blake-hash']);
const createBundle = (config, options) => ({
...config,
input: options.input,
external: Object.keys(pkg.dependencies || {}).filter(dep => {
if (FORCE_BUNDLE_DEPS.has(dep)) return false;
return options.includeSnarkjs ? true : dep !== 'snarkjs';
}),
onwarn(warning, warn) {
// Suppress circular dependency warnings from stream polyfills
// These are expected and harmless in Node.js stream implementations
if (
warning.code === 'CIRCULAR_DEPENDENCY' &&
(warning.message.includes('_stream_') ||
warning.message.includes('readable-stream'))
) {
return;
}
// Show all other warnings
warn(warning);
}
});
const createOutput = (name, options) => [
{ file: `dist/${name}.js`, format: 'cjs', sourcemap: true },
{ file: `dist/${name}.mjs`, format: 'es', sourcemap: true },
{
name: options.umdName,
file: `dist/${name}.umd.js`,
format: 'umd',
globals: {
'@vocdoni/davinci-contracts': 'davinciContracts',
ethers: 'ethers',
snarkjs: 'snarkjs',
'@ethereumjs/common': 'ethereumjsCommon'
// NOTE: circomlibjs/blake-hash/buffer are now bundled, so no globals needed for them.
}
}
];
export default [
// Main bundle
createBundle(
{
plugins: [
json(),
commonjs(),
resolve({ browser: true, preferBuiltins: false }),
nodePolyfills(),
// 1) Transpile TS->JS first so inject can parse reliably
esbuild({ target: 'esnext' }),
// 2) Inject a lexical Buffer import wherever Buffer is referenced.
// This fixes blake-hash even if globalThis.Buffer is missing.
inject({
Buffer: ['buffer', 'Buffer']
})
],
output: createOutput('index', { umdName: 'VocdoniSDK' })
},
{
input: 'src/index.ts',
includeSnarkjs: true
}
),
// Main types bundle
createBundle(
{
plugins: [dts()],
output: { file: 'dist/index.d.ts', format: 'es' }
},
{
input: 'src/index.ts',
includeSnarkjs: true
}
),
// Contracts types bundle
createBundle(
{
plugins: [dts()],
output: { file: 'dist/contracts.d.ts', format: 'es' }
},
{
input: 'src/contracts/index.ts',
includeSnarkjs: true
}
),
// Sequencer types bundle
createBundle(
{
plugins: [dts()],
output: { file: 'dist/sequencer.d.ts', format: 'es' }
},
{
input: 'src/sequencer/index.ts',
includeSnarkjs: true
}
)
];