build-local
Build local
A preview request ends at a usable preview of the working tree, uncommitted changes included. TDD, cleanup, code review, commits, and production or deployment builds run only when the user requested them or the selected preview mode requires them. On follow-up visual edits, reuse the verified server and inspect the changed result; repeat setup only when its inputs changed.
Process ownership. You own only the server process you start. Keep an ownership record you can consult later in the session: the background process handle your tools provide when available, otherwise its exact PID and command, plus a precise way to stop it. Stop only owned processes, never by broad name. Leave every other server running, including one whose ownership is unclear, and choose another port.
Select and prepare
- Identify the working tree containing the user's changes and the project root within it. Identify the package manager from its manifest and lockfile, then read the scripts and port settings needed for the selected preview mode. Run commands from that working tree so the preview includes its current files.
- Honor the target and mode named by the user. Otherwise, prefer the project's development server for inspecting edits and iterating. Use a production build and its compatible serve command when the user wants to check built output or the project requires it.
- Inspect any existing ownership record. Reuse a server only when the working tree, project root, mode, command, PID relationship, port, and URL all match, and verify its freshness as described in the next section before presenting its URL.
- For production previews, build the current files before serving them. Reuse existing output only when there is evidence its source files, dependencies, and build configuration are unchanged. For development previews, run the preparation required by the project's development command. Keep a last-known-good instance available when the project supports isolated output. Pass the port through the project's supported option or environment variable.
Completion criterion: the working tree, selected target and mode, required preparation or build, serve command, port, and process ownership are recorded before a server starts.
Coordinate with tests
Before starting a preview that will coexist with browser tests, inspect the test runner's server command, port, reuse/external-URL setting, and framework lock/output directory. Choose one server owner: let tests start their server, or point them at a verified owned preview using the supported configuration. Another port alone may still collide on the framework lock. If tests require exclusive ownership, stop the owned preview first and restore it afterward when the user still needs it.