Dev servers and production builds from one folder
A Vite + React page and a Hono API that run as dev servers, as a production build in the same lane with devlanes start --profile prod, and as a second project, example-dev-and-prod-release, declared in devlanes.prod.yaml with extends: devlanes.yaml. Per-machine changes go in devlanes.local.yaml.
Requirements
Section titled “Requirements”- devlanes, with
devlanes setuprun once - Node 22.12 or later
Run it
Section titled “Run it”cd workflows-dev-and-proddevlanes startdevlanes start --no-ui prints the start as text:
example-dev-and-prod@0 (main): 2/2 readyready api http://127.0.0.1:20460 https://api.example-dev-and-prod.localhostready web http://127.0.0.1:20461 https://example-dev-and-prod.localhostOpen https://example-dev-and-prod.localhost. The page has a card for web and one for api, with the npm script each one runs, NODE_ENV, the profile and the project file.
During a start
Section titled “During a start”installrunsnpm install --include=devat the workspace root on the lane’s first start (when: lane.create).buildruns only when theprodprofile is active (profiles: [prod]), so a plain start skips it.- The
defaultprofile selects every service withinclude: ["*"]and addsNODE_ENV: developmentandAPP_PROFILE: defaultto their env. apirunsnpm run dev(tsx watch src/index.ts) at https://api.example-dev-and-prod.localhost.webrunsnpm run dev(vite) at https://example-dev-and-prod.localhost with the flagspreset: viteadds. Both are ready once/healthzanswers.webgets/healthz,/laneand/modefrom the plugin inapps/web/plugins/laneRoutes.ts, which works inviteandvite previewalike.
The page calls the API cross-origin at the api_url from /mode (${{ services.api.public_url }}). The API allows only the origins in DEVLANES_ORIGINS, so another lane’s page gets no answer.
The prod profile
Section titled “The prod profile”prod runs the same services in the same lane from built code. Its build task runs npm run build at the root: tsc for the API and tsc --noEmit && vite build for the page. run_scripts: { dev: start } makes every service whose run_script names dev run start from the same package.json: node dist/index.js for api and vite preview for web. preset: vite adds the same --port flags to vite preview, so the hostname stays the same.
A start leaves running services alone, so on a lane that already runs the dev servers devlanes start --profile prod prints already running (nothing started). Stop the lane first:
devlanes stopdevlanes start --profile prod --no-uiexample-dev-and-prod@0 (main): 2/2 readyready api http://127.0.0.1:20460 https://api.example-dev-and-prod.localhostready web http://127.0.0.1:20461 https://example-dev-and-prod.localhostThe page now says as a production bundle that vite preview serves, with npm script start, bundle production and NODE_ENV production, and the api card says dist/*.js built by tsc:
curl -fsS https://api.example-dev-and-prod.localhost/mode{ "script": "start", "runs_from": "dist", "node_env": "production", "profile": "prod", "project_file": "devlanes.yaml", "log_level": "info"}devlanes stop forgets the lane’s profiles, so devlanes stop and a plain devlanes start bring the dev servers back.
A second project file
Section titled “A second project file”devlanes.prod.yaml extends devlanes.yaml and names another project, example-dev-and-prod-release. Its default profile adds run_scripts: { dev: start } and NODE_ENV: production, and its build task runs with profiles: [default], so a plain start of that project always builds and serves the bundle. devlanes only finds devlanes.yaml by itself, so name the file the first time:
devlanes --file devlanes.prod.yaml startdevlanes -p example-dev-and-prod-release statusexample-dev-and-prod-release LANE BRANCH STATE SERVICES CPU MEM URL 0 main running 2/2 0.0% 121.7 MiB https://example-dev-and-prod-release.localhost
UNIT STATE PORT CPU MEM URL api ready 20530 0.0% 51.9 MiB https://api.example-dev-and-prod-release.localhost web ready 20531 0.0% 69.7 MiB https://example-dev-and-prod-release.localhost build exited – – – install exited – – –It runs next to example-dev-and-prod in the same worktree with its own ports and hostnames. https://example-dev-and-prod-release.localhost shows This is lane 0 of example-dev-and-prod-release., profile default and project file devlanes.prod.yaml, while https://example-dev-and-prod.localhost keeps its dev servers. After the first start, -p example-dev-and-prod-release finds the project from anywhere, as in devlanes -p example-dev-and-prod-release logs api --tail 5.
Both projects use the files of one folder:
- The page’s build output goes to
WEB_OUT_DIR, whichdevlanes.yamlsets to${{ lane.data_path }}/web-dist. The lane data folder is~/.devlanes/data/<project>/<lane id>, so each lane of each project serves its own bundle, and the page’sbuild outputrow shows where. Adist/inapps/webwould be one folder for all of them, and one project’s build would replace the bundle the other serves. - The API’s build output goes to
apps/api/dist, next tonode_modules, where Node findshono. Every lane builds the same files there, since nothing lane-specific goes into them. - Every lane of both projects installs into the same
node_modules.installusesnpm installrather thannpm ci, which would delete it under a running Vite. It uses--include=devbecause profileenvreaches tasks too: withNODE_ENV=productionnpm leaves out devDependencies such asviteandtypescript, and removes them from the shared folder.
Local overrides
Section titled “Local overrides”devlanes.local.example.yaml turns web off with autostart: false, adds LOG_LEVEL: debug to api’s env and adds a scratch service (apps/scratch) that only this machine runs. Copy it to devlanes.local.yaml, which Git ignores:
cp devlanes.local.example.yaml devlanes.local.yamldevlanes statusexample-dev-and-prod LANE BRANCH STATE SERVICES CPU MEM URL 0 main running 2/3 0.0% 130.0 MiB https://example-dev-and-prod.localhost (config changed: 1 changed, 1 added; devlanes reload --lane example-dev-and-prod@0 applies it)
UNIT STATE PORT CPU MEM URL api ready 20460 0.0% 66.4 MiB https://api.example-dev-and-prod.localhost web ready 20461 0.0% 63.6 MiB https://example-dev-and-prod.localhost scratch idle 20462 – – https://scratch.example-dev-and-prod.localhost build exited – – – install exited – – – api: env LOG_LEVEL changed in the project file scratch: added to the project filedevlanes debug config prints the merged config, starting with a # from line per file in merge order: devlanes.yaml, then devlanes.local.yaml. For devlanes -p example-dev-and-prod-release debug config the list is devlanes.yaml, devlanes.local.yaml, devlanes.prod.yaml, so the local file reaches the release project too, and devlanes -p example-dev-and-prod-release status shows the same two changes.
devlanes reload --no-uiexample-dev-and-prod@0 (main): 2/2 readyready api http://127.0.0.1:20460 https://api.example-dev-and-prod.localhostready scratch http://127.0.0.1:20462 https://scratch.example-dev-and-prod.localhostThe page’s api card shows LOG_LEVEL debug, devlanes logs api shows a debug: GET /mode line per request, and https://scratch.example-dev-and-prod.localhost answers with its lane JSON and the API’s http://127.0.0.1 address from ${{ services.api.url }}.
web keeps running, because autostart: false only skips a service the lane did not run before. After devlanes stop and devlanes start, devlanes status lists web as stopped and https://example-dev-and-prod.localhost answers with the proxy’s DL201 Service not running page. devlanes start web starts it by name. Delete devlanes.local.yaml and run devlanes reload to go back.
Try next
Section titled “Try next”Start a second lane in a new worktree:
Terminal window git worktree add ../examples-checkout -b feat/checkoutcd ../examples-checkout/workflows-dev-and-proddevlanes startThe new worktree has no
node_modules, soinstallruns there, and the lane uses the primary worktree’sdevlanes.local.yamlif you made one.To get a second lane without a worktree, run
devlanes lane new --name example-dev-and-prod-review --startin this folder. https://example-dev-and-prod1.localhost showsThis is lane 1 of example-dev-and-prod.with its API at https://api.example-dev-and-prod1.localhost.Run lane 1 in prod while lane 0 keeps its dev servers:
devlanes stop --lane example-dev-and-prod-review, thendevlanes start --lane example-dev-and-prod-review --profile prod --no-ui. https://example-dev-and-prod1.localhost showsvite previewwith a build output folder of its own, and https://example-dev-and-prod.localhost still showsvite dev server.Remove the lanes with
devlanes lane clean example-dev-and-prod-review --yes,devlanes lane clean 0 --yesanddevlanes -p example-dev-and-prod-release lane clean 0 --yes.
devlanes.yaml:installandbuildtasks,apiandweb, thedefaultandprodprofiles,WEB_OUT_DIRin the lane data folder.devlanes.prod.yaml: theexample-dev-and-prod-releaseproject, building and serving the bundle on a plain start.devlanes.local.example.yaml: per-machine overrides to copy todevlanes.local.yaml.apps/api/src/: the Hono API, with/,/mode,/api/releases,/laneand/healthz.apps/web/vite.config.ts:build.outDirfromWEB_OUT_DIR, and thelaneRoutesplugin fromplugins/.