---
title: "Dev servers and production builds from one folder"
url: https://devlanes.run/examples/workflows-dev-and-prod/
description: "Switch a lane between dev servers and a production build with a profile, and keep personal settings in devlanes.local.yaml."
---

# Dev servers and production builds from one folder

A Vite + React page and a [Hono](https://hono.dev) 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

- devlanes, with `devlanes setup` run once
- Node 22.12 or later

## Run it

```sh
cd workflows-dev-and-prod
devlanes start
```

`devlanes start --no-ui` prints the start as text:

```text
example-dev-and-prod@0 (main): 2/2 ready
ready api http://127.0.0.1:20460 https://api.example-dev-and-prod.localhost
ready web http://127.0.0.1:20461 https://example-dev-and-prod.localhost
```

Open 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

1. `install` runs `npm install --include=dev` at the workspace root on the lane's first start (`when: lane.create`).
2. `build` runs only when the `prod` profile is active (`profiles: [prod]`), so a plain start skips it.
3. The `default` profile selects every service with `include: ["*"]` and adds `NODE_ENV: development` and `APP_PROFILE: default` to their env.
4. `api` runs `npm run dev` (`tsx watch src/index.ts`) at https://api.example-dev-and-prod.localhost. `web` runs `npm run dev` (`vite`) at https://example-dev-and-prod.localhost with the flags `preset: vite` adds. Both are ready once `/healthz` answers. `web` gets `/healthz`, `/lane` and `/mode` from the plugin in `apps/web/plugins/laneRoutes.ts`, which works in `vite` and `vite preview` alike.

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

`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:

```sh
devlanes stop
devlanes start --profile prod --no-ui
```

```text
example-dev-and-prod@0 (main): 2/2 ready
ready api http://127.0.0.1:20460 https://api.example-dev-and-prod.localhost
ready web http://127.0.0.1:20461 https://example-dev-and-prod.localhost
```

The 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`:

```sh
curl -fsS https://api.example-dev-and-prod.localhost/mode
```

```json
{
  "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

`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:

```sh
devlanes --file devlanes.prod.yaml start
devlanes -p example-dev-and-prod-release status
```

```text
example-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`, which `devlanes.yaml` sets 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's `build output` row shows where. A `dist/` in `apps/web` would 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 to `node_modules`, where Node finds `hono`. 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`. `install` uses `npm install` rather than `npm ci`, which would delete it under a running Vite. It uses `--include=dev` because profile `env` reaches tasks too: with `NODE_ENV=production` npm leaves out devDependencies such as `vite` and `typescript`, and removes them from the shared folder.

## 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:

```sh
cp devlanes.local.example.yaml devlanes.local.yaml
devlanes status
```

```text
example-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 file
```

`devlanes 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.

```sh
devlanes reload --no-ui
```

```text
example-dev-and-prod@0 (main): 2/2 ready
ready api http://127.0.0.1:20460 https://api.example-dev-and-prod.localhost
ready scratch http://127.0.0.1:20462 https://scratch.example-dev-and-prod.localhost
```

The 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

- Start a second lane in a new worktree:

  ```sh
  git worktree add ../examples-checkout -b feat/checkout
  cd ../examples-checkout/workflows-dev-and-prod
  devlanes start
  ```

  The new worktree has no `node_modules`, so `install` runs there, and the lane uses the primary worktree's `devlanes.local.yaml` if you made one.

- To get a second lane without a worktree, run `devlanes lane new --name example-dev-and-prod-review --start` in this folder. https://example-dev-and-prod1.localhost shows `This 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`, then `devlanes start --lane example-dev-and-prod-review --profile prod --no-ui`. https://example-dev-and-prod1.localhost shows `vite preview` with a build output folder of its own, and https://example-dev-and-prod.localhost still shows `vite dev server`.
- Remove the lanes with `devlanes lane clean example-dev-and-prod-review --yes`, `devlanes lane clean 0 --yes` and `devlanes -p example-dev-and-prod-release lane clean 0 --yes`.

## Files

- [`devlanes.yaml`](https://github.com/devlanes-run/examples/blob/d2a99f076179db99581cef85453a58b788f3970b/workflows-dev-and-prod/devlanes.yaml): `install` and `build` tasks, `api` and `web`, the `default` and `prod` profiles, `WEB_OUT_DIR` in the lane data folder.
- [`devlanes.prod.yaml`](https://github.com/devlanes-run/examples/blob/d2a99f076179db99581cef85453a58b788f3970b/workflows-dev-and-prod/devlanes.prod.yaml): the `example-dev-and-prod-release` project, building and serving the bundle on a plain start.
- [`devlanes.local.example.yaml`](https://github.com/devlanes-run/examples/blob/d2a99f076179db99581cef85453a58b788f3970b/workflows-dev-and-prod/devlanes.local.example.yaml): per-machine overrides to copy to `devlanes.local.yaml`.
- [`apps/api/src/`](https://github.com/devlanes-run/examples/blob/d2a99f076179db99581cef85453a58b788f3970b/workflows-dev-and-prod/apps/api/src): the Hono API, with `/`, `/mode`, `/api/releases`, `/lane` and `/healthz`.
- [`apps/web/vite.config.ts`](https://github.com/devlanes-run/examples/blob/d2a99f076179db99581cef85453a58b788f3970b/workflows-dev-and-prod/apps/web/vite.config.ts): `build.outDir` from `WEB_OUT_DIR`, and the `laneRoutes` plugin from `plugins/`.

## Docs

- [Service patterns: several projects in one directory](/docs/guides/services/#several-projects-in-one-directory)
- [Ports and environment: local overrides](/docs/guides/ports-and-env/#local-overrides)
- [Ports and environment: extending another project file](/docs/guides/ports-and-env/#extending-another-project-file)
- [Run and run_script: profiles that swap scripts](/docs/guides/run-scripts/#profiles-that-swap-scripts)
- [Framework presets: Vite](/docs/guides/presets/#vite)
