feat(build): add preview as an alias for serve in cli (#1651)

* feat(build): add preview as an alias for serve in cli
* docs: recommend using preview instead of serve
pull/1584/head
Divyansh Singh 2 years ago committed by GitHub
parent dc596621cf
commit 4ba33dac60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,7 +10,7 @@ The following guides are based on some shared assumptions:
{
"scripts": {
"docs:build": "vitepress build docs",
"docs:serve": "vitepress serve docs"
"docs:preview": "vitepress preview docs"
}
}
```
@ -34,22 +34,22 @@ If your site is to be served at a subdirectory (`https://example.com/subdir/`),
- Once you've built the docs, you can test them locally by running:
```sh
$ yarn docs:serve
$ yarn docs:preview
```
The `serve` command will boot up a local static web server that will serve the files from `.vitepress/dist` at `http://localhost:4173`. It's an easy way to check if the production build looks fine in your local environment.
The `preview` command will boot up a local static web server that will serve the files from `.vitepress/dist` at `http://localhost:4173`. It's an easy way to check if the production build looks fine in your local environment.
- You can configure the port of the server by passing `--port` as an argument.
```json
{
"scripts": {
"docs:serve": "vitepress serve docs --port 8080"
"docs:preview": "vitepress preview docs --port 8080"
}
}
```
Now the `docs:serve` method will launch the server at `http://localhost:8080`.
Now the `docs:preview` method will launch the server at `http://localhost:8080`.
## Netlify, Vercel, AWS Amplify, Cloudflare Pages, Render

@ -63,7 +63,7 @@ Add some scripts to `package.json`.
"scripts": {
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:serve": "vitepress serve docs"
"docs:preview": "vitepress preview docs"
},
...
}

@ -62,12 +62,12 @@
"format": "prettier --check --write .",
"format-fail": "prettier --check .",
"check": "run-s format-fail build test",
"test": "run-p --aggregate-output test-unit test-serve test-build",
"test": "run-p --aggregate-output test-unit test-preview test-build",
"test-unit": "vitest run -r __tests__/unit",
"test-serve": "vitest run -r __tests__/e2e",
"test-build": "VITE_TEST_BUILD=1 pnpm test-serve",
"debug-serve": "DEBUG=1 vitest -r __tests__/e2e",
"debug-build": "VITE_TEST_BUILD=1 pnpm debug-serve",
"test-preview": "vitest run -r __tests__/e2e",
"test-build": "VITE_TEST_BUILD=1 pnpm test-preview",
"debug-preview": "DEBUG=1 vitest -r __tests__/e2e",
"debug-build": "VITE_TEST_BUILD=1 pnpm debug-preview",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"release": "node scripts/release.js",
"docs": "run-p dev docs-dev",
@ -75,7 +75,7 @@
"docs-debug": "node --inspect-brk ./bin/vitepress dev docs",
"docs-build": "run-s build docs-build-only",
"docs-build-only": "node ./bin/vitepress build docs",
"docs-serve": "node ./bin/vitepress serve docs"
"docs-preview": "node ./bin/vitepress preview docs"
},
"dependencies": {
"@docsearch/css": "^3.3.0",

@ -32,7 +32,7 @@ if (!command || command === 'dev') {
console.error(c.red(`build error:\n`), err)
process.exit(1)
})
} else if (command === 'serve') {
} else if (command === 'serve' || command === 'preview') {
serve(argv).catch((err) => {
console.error(c.red(`failed to start server. error:\n`), err)
process.exit(1)

Loading…
Cancel
Save