forked from permaweb/ao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
50 lines (45 loc) · 1.21 KB
/
esbuild.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
import { readFileSync } from 'node:fs'
import * as esbuild from 'esbuild'
/**
* By importing from manifest, build will always be in sync with the manifest
*/
const manifest = JSON.parse(readFileSync('./package.json'))
/**
* Some dependencies are ESM only, and so cannot be required from a CJS project.
* So for those dependencies, we make sure to include them in distribution bundle,
* so CJS projects can use the code, without having to import the dependency at runtime.
*
* ie. hyper-async
*/
function allDepsExcept (excluded = []) {
return Object.keys(manifest.dependencies).filter((dep) =>
!excluded.includes(dep)
)
}
// CJS
await esbuild.build({
entryPoints: ['src/index.js'],
platform: 'node',
format: 'cjs',
external: allDepsExcept(['hyper-async']),
bundle: true,
outfile: manifest.exports['.'].require
})
// ESM
await esbuild.build({
entryPoints: ['src/index.js'],
platform: 'node',
format: 'esm',
external: allDepsExcept(['hyper-async']),
bundle: true,
outfile: manifest.exports['.'].import
})
// Browser ESM
await esbuild.build({
entryPoints: ['src/index.browser.js'],
platform: 'browser',
format: 'esm',
bundle: true,
minify: false,
outfile: manifest.exports['.'].browser
})