Skip to content

Latest commit

 

History

History
90 lines (59 loc) · 2.78 KB

File metadata and controls

90 lines (59 loc) · 2.78 KB

ResX Demo

Install

The demo uses the local rescript-x package from the repo root, so install both layers:

bun install
cd demo
bun install

The demo postinstall script creates demo/node_modules/rescript-x as a symlink back to the repo root. That keeps the demo reproducible without recursively copying the whole repository into node_modules.

Local Run

cd demo
bun run dev

Open the Vite URL that it prints, typically http://localhost:9000. In dev, the browser should use the Vite server origin rather than the raw Bun app port.

For a production-style local run:

cd demo
bun run build
NODE_ENV=production bun run src/Demo.js

The app listens on PORT when it is set, and falls back to 4444.

Docker Deploy

Build from the repo root so the Docker build can include the parent rescript-x package:

docker build -f demo/Dockerfile -t resx-demo .

Run the image:

docker run --rm -p 4444:4444 -e PORT=4444 resx-demo

What the image contains:

  • A Bun single-file executable at /app/demo-app
  • The Vite output in /app/dist
  • No Bun toolchain or source tree in the runtime image

The container has already been verified to serve both /start and hashed asset routes from /assets/....

Direct SFE Deploy

Build the executable locally:

cd demo
bun run build:sfe

That produces:

  • build/demo-app
  • dist/

Deploy both of those together. This demo currently uses the default staticAssetRoutes.mode: "filesystem", so the executable is not fully self-contained and still serves generated assets from ./dist.

Run it like this:

cd demo
PORT=4444 NODE_ENV=production ./build/demo-app

Important runtime notes:

  • Keep dist/ in the current working directory when you start the executable, or set your service WorkingDirectory to the directory that contains dist/.
  • Files from demo/assets/ are fingerprinted into dist/assets/.
  • Files from demo/public/ are also emitted into dist/, so you do not need to deploy public/ separately.
  • If you want to offload assets to a CDN or another static host, you need to change the generated asset URLs and static route strategy. The current setup expects the app process to serve dist/ itself.

If you want a truly standalone executable instead, switch the demo Vite config to staticAssetRoutes: { mode: "embedded" } before building. That makes ResX generate embedded-file-backed static routes for bun build --compile, so the resulting executable can serve its generated assets without a sidecar dist/ tree.

Platform note:

  • Bun single-file executables are target-platform specific. If you want to deploy the SFE directly to Linux, build it on Linux for the correct architecture. The Docker image is the safest path because it already builds the Linux executable in-container.