You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 435c41f
Browse filesBrowse the repository at this point in the historyBrowse files
@@ -39,9 +39,29 @@ Some Nitro presets do not produce a server that can be run locally. For those, t
39
39
|`-e, --extends=<layer-name>...`|| Extend from a Nuxt layer |
40
40
|`-p, --port=<port>`|| Port to listen on (default: `NUXT_PORT \|\| NITRO_PORT \|\| PORT`) |
41
41
|`-h, --host=<host>`|| Host to listen on (default: `NUXT_HOST \|\| NITRO_HOST \|\| HOST`) |
42
+
|`--takeover`|| Stop a preview server already running on this project and take its place |
43
+
|`--no-takeover`|| Never stop a preview server already running on this project |
44
+
|`--strictPort`|`false`| Exit if the requested port is unavailable instead of using another one |
42
45
|`--dotenv=<path>...`|| Path to `.env` file to load, relative to the root directory. Can be repeated, with later files taking precedence. |
43
46
<!--/preview-opts-->
44
47
48
+
## Taking over a running preview
49
+
50
+
A preview records itself in `node_modules/.cache/nuxt/preview`, so a second `nuxt preview` for the same project deals with the one already running the way [`nuxt dev`](/docs/api/commands/dev#taking-over-a-running-dev-server) deals with a running dev server:
51
+
52
+
| Running preview was started | New preview is started | What happens |
| without a terminal | without a terminal | It is stopped, and the new one takes its port. |
55
+
| without a terminal | in a terminal | You are asked, defaulting to taking it over. |
56
+
| in a terminal | without a terminal | The new one exits, saying where the running one is. |
57
+
| in a terminal | in a terminal | You are asked, defaulting to not starting. |
58
+
59
+
Pass `--takeover` to always stop it and start in its place, or `--no-takeover` to never do so. Choosing "Start anyway" at the prompt, or passing a different `--port`, runs a second preview alongside it instead.
60
+
61
+
When another server, including `nuxt dev`, is using the requested port, the preview automatically uses another free port without stopping that server. Pass `--strictPort` to exit instead. The requested port comes from `--port`, `NUXT_PORT`, `NITRO_PORT`, or `PORT`, defaulting to `3000`.
62
+
63
+
Port selection applies to static previews and preview commands that run directly with Node.js, Bun, or Deno. Other preview commands choose their own port.
64
+
45
65
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
0 commit comments