Skip to content

Commit 0d583d9

Browse files
feat: add serve command (#5351)
* feat: add `--serve` flag to `dev` command * refactor: simplify internal directory clean up * refactor: load built functions * refactor: make things nicer * refactor: add const * feat: show debug message * refactor: rename variable * chore: add `extract-zip` dependency * chore: update snapshots * refactor: conditionally set `quiet` flag * refactor: simplify code * chore: update docs * refactor: rename flag to `prod` * refactor: update message * feat: do not set `NETLIFY_DEV` when `prod` is set * chore: remove lint exceptions * Apply suggestions from code review Co-authored-by: Matt Kane <[email protected]> * refactor: treat `NETLIFY_DEV` consistently across function types * refactor: add `internal` source for env vars * fix: handle internal vars correctly * chore: update docs * refactor: remove unused variable * feat: set `context=production` when `prod` is used * refactor: add beta label * feat: create separate `serve` command * Update src/commands/serve/serve.mjs Co-authored-by: Matt Kane <[email protected]> * refactor: remove unused flags * refactor: abort server when build fails * refactor: always start functions server * chore: remove ESLint directive * fix: fix imports * refactor: always start functions server * refactor: ensure internal functions directory * refactor: reinstate functions server check * refactor: add missing import * fix: fix imports * refactor: move logic for ensuring internal functions directory * chore: fix test * chore: update docs * chore: update snapshot * refactor: add log message * Update src/commands/serve/serve.mjs Co-authored-by: Matt Kane <[email protected]> * chore: update docs Co-authored-by: Matt Kane <[email protected]>
1 parent 2b7045e commit 0d583d9

22 files changed

+923
-658
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ See the [CLI command line reference](https://cli.netlify.com/commands/) to get s
3434
- [login](#login)
3535
- [open](#open)
3636
- [recipes](#recipes)
37+
- [serve](#serve)
3738
- [sites](#sites)
3839
- [status](#status)
3940
- [switch](#switch)
@@ -219,6 +220,10 @@ Open settings for the site linked to the current folder
219220
| [`recipes:list`](/docs/commands/recipes.md#recipeslist) | (Beta) List the recipes available to create and modify files in a project |
220221

221222

223+
### [serve](/docs/commands/serve.md)
224+
225+
(Beta) Build the site for production and serve locally. This does not watch the code for changes, so if you need to rebuild your site then you must exit and run `serve` again.
226+
222227
### [sites](/docs/commands/sites.md)
223228

224229
Handle various site operations

docs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ Open settings for the site linked to the current folder
168168
| [`recipes:list`](/docs/commands/recipes.md#recipeslist) | (Beta) List the recipes available to create and modify files in a project |
169169

170170

171+
### [serve](/docs/commands/serve.md)
172+
173+
(Beta) Build the site for production and serve locally. This does not watch the code for changes, so if you need to rebuild your site then you must exit and run `serve` again.
174+
171175
### [sites](/docs/commands/sites.md)
172176

173177
Handle various site operations

docs/commands/dev.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ netlify dev
3030
- `live` (*boolean*) - start a public live session
3131
- `offline` (*boolean*) - disables any features that require network access
3232
- `port` (*string*) - port of netlify dev
33-
- `prod` (*boolean*) - (Beta) build the site for production and serve locally
3433
- `sessionId` (*string*) - (Graph) connect to cloud session with ID [sessionId]
3534
- `targetPort` (*string*) - port of target app server
3635
- `debug` (*boolean*) - Print debugging information

docs/commands/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ Open settings for the site linked to the current folder
147147
| [`recipes:list`](/docs/commands/recipes.md#recipeslist) | (Beta) List the recipes available to create and modify files in a project |
148148

149149

150+
### [serve](/docs/commands/serve.md)
151+
152+
(Beta) Build the site for production and serve locally. This does not watch the code for changes, so if you need to rebuild your site then you must exit and run `serve` again.
153+
150154
### [sites](/docs/commands/sites.md)
151155

152156
Handle various site operations

src/commands/base-command.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,7 @@ export default class BaseCommand extends Command {
510510
* @returns {string}
511511
*/
512512
getDefaultContext() {
513-
const { prod } = this.opts()
514-
const isDevCommand = ['dev', 'dev:exec'].includes(this.name())
515-
516-
if (isDevCommand && prod) {
513+
if (this.name() === 'serve') {
517514
return 'production'
518515
}
519516

0 commit comments

Comments
 (0)