-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathesbuild.config.js
43 lines (39 loc) · 1.18 KB
/
esbuild.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
import esbuild from 'esbuild'
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
import alias from 'esbuild-plugin-alias'
import { readFile } from 'fs/promises'
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
// import {exports as pkgExports} from './package.json' assert {type: 'json'}
const { exports: pkgExports } = JSON.parse(
await readFile(new URL('./package.json', import.meta.url))
)
const entryPoints = new Set()
for (const path of Object.values(pkgExports)) {
entryPoints.add(path.replace(/^\.\/dist/, 'src'))
}
esbuild
.build({
target: 'es2018',
entryPoints: [...entryPoints],
bundle: true,
platform: 'browser',
outdir: 'dist',
sourcemap: true,
splitting: true,
minify: true,
plugins: [
alias({ crypto: require.resolve('crypto-browserify') }),
NodeModulesPolyfillPlugin(),
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
}),
],
format: 'esm',
})
.catch((error) => {
console.error(error)
process.nextTick(() => process.exit(1))
})