'use strict' const { build } = require('esbuild') const { mkdirSync } = require('fs') mkdirSync('public', { recursive: true }) // occulto uses require('crypto') internally; shim it to the browser Web Crypto API const cryptoBrowserShim = { name: 'crypto-browser-shim', setup(b) { b.onResolve({ filter: /^crypto$/ }, () => ({ path: 'crypto', namespace: 'crypto-browser-shim', })) b.onLoad({ filter: /.*/, namespace: 'crypto-browser-shim' }, () => ({ contents: 'module.exports = { webcrypto: globalThis.crypto }', })) }, } build({ entryPoints: ['src/customer.js', 'src/link.js'], bundle: true, outdir: 'public', format: 'iife', target: ['es2020'], minify: true, platform: 'browser', plugins: [cryptoBrowserShim], }) .then(() => console.log('✓ Bundles built: public/customer.js, public/link.js')) .catch((err) => { console.error(err); process.exit(1) })