diff --git a/.gitignore b/.gitignore index ac1e8f7..34a9938 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules *.log .DS_Store +dist diff --git a/README.md b/README.md index 34de0ba..02f7a51 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,12 @@ Built with Bun and [OpenTUI](https://github.com/anomalyco/opentui) (React). ```sh git clone --recurse-submodules && cd tui3 -bun install # also links the pinned T3 Code packages into node_modules +bun install # also links the pinned T3 Code packages into node_modules and builds dist/ bun link # optional: puts `tui3` on your PATH ``` +`tui3` runs the bundle in `dist/`, which uses over 100 MB less memory than the sources. After pulling changes, run `bun run build` (or `bun install`) to rebuild it; `bun run dev` runs the sources directly. + ## Use ```sh diff --git a/package.json b/package.json index ec2a363..230d06b 100644 --- a/package.json +++ b/package.json @@ -4,14 +4,15 @@ "private": true, "type": "module", "bin": { - "tui3": "./src/bin.ts" + "tui3": "./dist/bin.js" }, "scripts": { "dev": "bun run src/bin.ts", + "build": "bun run scripts/build.ts", "typecheck": "tsc --noEmit", "lint": "biome lint src test", "test": "bun test", - "postinstall": "bun run scripts/link-vendor.ts" + "postinstall": "bun run scripts/link-vendor.ts && bun run scripts/build.ts" }, "dependencies": { "@opentui/core": "0.2.7", diff --git a/scripts/build.ts b/scripts/build.ts new file mode 100644 index 0000000..503bd9b --- /dev/null +++ b/scripts/build.ts @@ -0,0 +1,21 @@ +// Bundles tui3 into dist/. Running the TypeScript sources makes Bun compile and keep +// hundreds of vendored modules at startup, which costs over 100 MB of memory. +import { rm } from "node:fs/promises"; +import { join } from "node:path"; + +const root = join(import.meta.dir, ".."); +const outdir = join(root, "dist"); +await rm(outdir, { recursive: true, force: true }); + +const builds = [ + join(root, "src/bin.ts"), + // OpenTUI starts its syntax highlighter from parser.worker.js beside the code that loads it. + join(root, "node_modules/@opentui/core/parser.worker.js"), +]; +for (const entrypoint of builds) { + const result = await Bun.build({ entrypoints: [entrypoint], outdir, target: "bun", minify: true }); + if (!result.success) { + for (const log of result.logs) console.error(log); + process.exit(1); + } +}