-
Notifications
You must be signed in to change notification settings - Fork 43
/
build.sh
executable file
·43 lines (38 loc) · 1.01 KB
/
build.sh
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
#!/bin/bash
# Generates browser compatible versions of the package with dependencies
# bundled as well as the type declaration.
set -euo pipefail
entrypoint=./src/opa.js
outdir=./dist
package=$(node -pe 'require("./package.json").name.split("/").pop()')
if [[ ! -x $(npm bin)/esbuild || ! -x $(npm bin)/tsc ]]; then
echo "Installing dependencies…"
npm install
fi
echo "Generating default browser build…"
npx esbuild $entrypoint \
--outfile=$outdir/$package-browser.js \
--bundle \
--sourcemap \
--minify \
--format=iife \
--platform=browser \
--define:global=window \
--global-name=opa \
--external:util
echo "Generating esm browser build…"
npx esbuild $entrypoint \
--outfile=$outdir/$package-browser.esm.js \
--bundle \
--sourcemap \
--minify \
--format=esm \
--platform=browser \
--define:global=window \
--external:util
echo "Generating TypeScript declaration file…"
npx tsc ./src/index.mjs \
--declaration \
--allowJs \
--emitDeclarationOnly \
--outDir $outdir/types