diff --git a/README.md b/README.md index 5ef525e..f01ff9e 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ bun run dev | Command | Description | | -------------- | ------------------------------------------------------------------------------ | | `bunext dev` | Start the development server with HMR and file watching. | -| `bunext build` | Bundle all pages for production. Outputs artifacts to `.bunext/public/pages/`. | +| `bunext build` | Bundle all pages for production. Outputs artifacts to `.bunext/public/pages/`. Resolves absolute paths in the artifact maps at the configured build root — see [BUNEXT_BUILD_ROOT_DIR](#environment-variables). | | `bunext start` | Start the production server using pre-built artifacts. | ### Running the CLI @@ -913,10 +913,21 @@ bun run server.ts ## Environment Variables -| Variable | Description | -| ------------------ | ------------------------------------------------------------------------------------------------ | -| `PORT` | Override the server port (takes precedence over config) | -| `BUNEXT_PUBLIC_*` | Any env var prefixed with `BUNEXT_PUBLIC_` is exposed to the client via `window.process.env` | +| Variable | Description | +| ---------------------- | ------------------------------------------------------------------------------------------------ | +| `PORT` | Override the server port (takes precedence over config) | +| `BUNEXT_PUBLIC_*` | Any env var prefixed with `BUNEXT_PUBLIC_` is exposed to the client via `window.process.env` | +| `BUNEXT_BUILD_ROOT_DIR` | Read by `bunext build` only. When set, the project root's absolute path is replaced with this value inside the artifact maps (`map.json` and `ssr-bundler-ctx-map.json`) before they are written. Use it when the project will be served from a different path than the one it was built at (e.g. building in CI at `/build/app` and running in a container mounted at `/app`). | + +### Build Root Directory + +Artifact maps store absolute filesystem paths. By default, `bunext build` records the build machine's current working directory as the root. If the project will be deployed or served from a different location, point the maps at the runtime root instead: + +```bash +BUNEXT_BUILD_ROOT_DIR=/app bun run build +``` + +Run `bunext start` from the directory matching `BUNEXT_BUILD_ROOT_DIR` so all recorded artifact paths resolve at request time. If unset, the path is left as-is and the runtime working directory must match the build directory. ### Public Environment Variables @@ -965,8 +976,9 @@ Running `bunext build`: 1. Sets `NODE_ENV=production`. 2. Runs ESBuild once with minification enabled. -3. Writes all bundled artifacts to `.bunext/public/pages/` and the artifact map to `.bunext/public/pages/map.json`. -4. Exits. +3. Writes all bundled artifacts to `.bunext/public/pages/` plus the artifact maps `.bunext/public/pages/map.json` and `.bunext/public/pages/ssr-bundler-ctx-map.json`. +4. Artifact maps store absolute paths anchored at the project root. If `BUNEXT_BUILD_ROOT_DIR` is set, every occurrence of the build directory is replaced with that value so the maps point at the deploy-time location (see [Build Root Directory](#build-root-directory)). +5. Exits. ### Production Server diff --git a/dist/functions/server/web-pages/grab-page-component.js b/dist/functions/server/web-pages/grab-page-component.js index 375fb52..20b0845 100644 --- a/dist/functions/server/web-pages/grab-page-component.js +++ b/dist/functions/server/web-pages/grab-page-component.js @@ -52,8 +52,6 @@ export default async function grabPageComponent(params) { throw new Error(errMsg); } let bundledMap = global.BUNEXT_BUNDLER_CTX_MAP[file_path]; - console.log("bundledMap", bundledMap); - console.log("file_path", file_path); if (!bundledMap?.path) { if (does_error_file_exist) { throw new Error(`Application Error. Please Check your components. ${match?.filePath} likely exists but has no exported module.`); diff --git a/package.json b/package.json index d6f27b2..4fbf0ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/bunext", - "version": "1.1.10", + "version": "1.1.11", "main": "dist/index.js", "module": "index.ts", "dependencies": { diff --git a/src/functions/server/web-pages/grab-page-component.tsx b/src/functions/server/web-pages/grab-page-component.tsx index 281b644..f08f9c2 100644 --- a/src/functions/server/web-pages/grab-page-component.tsx +++ b/src/functions/server/web-pages/grab-page-component.tsx @@ -92,9 +92,6 @@ export default async function grabPageComponent( let bundledMap = global.BUNEXT_BUNDLER_CTX_MAP[file_path]; - console.log("bundledMap", bundledMap); - console.log("file_path", file_path); - if (!bundledMap?.path) { if (does_error_file_exist) { throw new Error(