Skip to content

Commit 0048e2b

Browse files
authored
feat(build): switch to vite 3, support clean urls and esm mode (vuejs#856)
1 parent b36656a commit 0048e2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1252
-1351
lines changed

.github/contributing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The easiest way to start testing out VitePress is to tweak the VitePress docs. Y
4848
$ pnpm run docs
4949
```
5050

51-
After executing the above command, visit http://localhost:3000 and try modifying the source code. You'll get live update.
51+
After executing the above command, visit http://localhost:5173 and try modifying the source code. You'll get live update.
5252

5353
If you don't need docs site up and running, you may start VitePress local dev environment with `pnpm run dev`.
5454

.github/workflows/release-tag.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
name: Release
2+
13
on:
24
push:
35
tags:
46
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
57

6-
name: Create Release
7-
88
jobs:
9-
build:
10-
name: Create Release
9+
release:
1110
runs-on: ubuntu-latest
11+
1212
steps:
13-
- name: Checkout code
14-
uses: actions/checkout@master
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
1516
- name: Create Release for Tag
1617
id: release_tag
1718
uses: yyx990803/release-tag@master

.github/workflows/test.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ on:
1616
jobs:
1717
test:
1818
runs-on: ubuntu-latest
19+
1920
strategy:
2021
matrix:
21-
node-version: [14, 16]
22+
node-version: [14, 16, 18]
23+
2224
steps:
2325
- name: Checkout
2426
uses: actions/checkout@v3
2527

2628
- name: Install pnpm
27-
uses: pnpm/[email protected]
28-
with:
29-
version: 7.0.1
29+
uses: pnpm/action-setup@v2
3030

3131
- name: Set node version to ${{ matrix.node_version }}
3232
uses: actions/setup-node@v3

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ dist
1010
node_modules
1111
pnpm-global
1212
TODOs.md
13+
.temp
14+
*.tgz

.prettierignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/docs
21
*.md
32
*.vue
43
dist

client.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// be able to reference vite/client in project root.
33
/// <reference types="vite/client" />
44

5-
export * from './dist/client'
5+
export * from './dist/client/index.js'

docs/.vitepress/config.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { defineConfig } from '../../src/node'
2-
32
import { version } from '../../package.json'
43

54
export default defineConfig({
@@ -8,6 +7,7 @@ export default defineConfig({
87
description: 'Vite & Vue powered static site generator.',
98

109
lastUpdated: true,
10+
cleanUrls: 'without-subfolders',
1111

1212
themeConfig: {
1313
nav: nav(),
@@ -58,9 +58,9 @@ function nav() {
5858
{
5959
text: 'Contributing',
6060
link: 'https://github.com/vuejs/vitepress/blob/main/.github/contributing.md'
61-
},
62-
],
63-
},
61+
}
62+
]
63+
}
6464
]
6565
}
6666

docs/config/app-configs.md

+25
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,28 @@ export default {
211211
titleTemplate: 'Vite & Vue powered static site generator'
212212
}
213213
```
214+
215+
## cleanUrls (Experimental)
216+
217+
- Type: `'disabled' | 'without-subfolders' | 'with-subfolders'`
218+
- Default: `'disabled'`
219+
220+
Allows removing trailing `.html` from URLs and, optionally, generating clean directory structure. Available modes:
221+
222+
| Mode | Page | Generated Page | URL |
223+
| :--------------------: | :-------: | :---------------: | :---------: |
224+
| `'disabled'` | `/foo.md` | `/foo.html` | `/foo.html` |
225+
| `'without-subfolders'` | `/foo.md` | `/foo.html` | `/foo` |
226+
| `'with-subfolders'` | `/foo.md` | `/foo/index.html` | `/foo` |
227+
228+
::: warning
229+
230+
Enabling this may require additional configuration on your hosting platform. For it to work, your server must serve the generated page on requesting the URL (see above table) **without a redirect**.
231+
232+
:::
233+
234+
```ts
235+
export default {
236+
cleanUrls: 'with-subfolders'
237+
}
238+
```

docs/config/introduction.md

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Place your configuration file at `.vitepress/config.js`. This is where all ViteP
1111
└─ package.json
1212
```
1313

14+
::: tip
15+
You can also use any of `.ts`, `.cjs`, `.mjs`, `.cts`, `.mts` as the config file extension.
16+
:::
17+
1418
VitePress comes with 2 types of configs. One is the [App Configs](./app-configs) which configures the site's fundamental features such as setting title of the site, or customize how markdown parser works. Second is the [Theme Config](./theme-configs) which configures the theme of the site, for example, adding a sidebar, or add features such as "Edit this page on GitHub" link.
1519

1620
There's also another configuration you may do in [Frontmatter](./frontmatter-configs). Frontmatter configs can override global configs defined on App Configs or Theme Configs for that specific page. However, there're several options that are only available at frontmatter as well.

docs/guide/deploying.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ If your site is to be served at a subdirectory (`https://example.com/subdir/`),
3737
$ yarn docs:serve
3838
```
3939

40-
The `serve` command will boot up a local static web server that will serve the files from `.vitepress/dist` at `http://localhost:5000`. It's an easy way to check if the production build looks fine in your local environment.
40+
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.
4141

4242
- You can configure the port of the server by passing `--port` as an argument.
4343

docs/guide/getting-started.md

+4-21
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,13 @@ $ yarn add --dev vitepress vue
3131
::: details Getting missing peer deps warnings?
3232
`@docsearch/js` has certain issues with its peer dependencies. If you see some commands failing due to them, you can try this workaround for now:
3333

34-
On Yarn v2/v3, add this inside your rc file (`.yarnrc.yml` by default):
35-
36-
```yaml
37-
packageExtensions:
38-
'@docsearch/react@*':
39-
peerDependenciesMeta:
40-
'@types/react':
41-
optional: true
42-
'react':
43-
optional: true
44-
'react-dom':
45-
optional: true
46-
```
47-
48-
On PNPM, add this in your `package.json`:
34+
If using PNPM, add this in your `package.json`:
4935

5036
```json
5137
"pnpm": {
5238
"peerDependencyRules": {
5339
"ignoreMissing": [
54-
"@algolia/client-search",
55-
"@types/react",
56-
"react",
57-
"react-dom"
40+
"@algolia/client-search"
5841
]
5942
}
6043
}
@@ -90,7 +73,7 @@ Serve the documentation site in the local server.
9073
$ yarn docs:dev
9174
```
9275

93-
VitePress will start a hot-reloading development server at `http://localhost:3000`.
76+
VitePress will start a hot-reloading development server at `http://localhost:5173`.
9477

9578
## Step. 4: Add more pages
9679

@@ -104,7 +87,7 @@ Let's add another page to the site. Create a file name `getting-started.md` alon
10487
└─ package.json
10588
```
10689

107-
Then, try to access `http://localhost:3000/getting-started` and you should see the content of `getting-started` is shown.
90+
Then, try to access `http://localhost:5173/getting-started.html` and you should see the content of `getting-started.md` is shown.
10891

10992
This is how VitePress works basically. The directory structure corresponds with the URL path. You add files, and just try to access it.
11093

docs/guide/migration-from-vitepress-0.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ If you're coming from VitePress 0.x version, there're several breaking changes d
1212
- `children` key is now named `items`.
1313
- Top level item may not contain `link` at the moment. We're planning to bring it back.
1414
- `repo`, `repoLabel`, `docsDir`, `docsBranch`, `editLinks`, `editLinkText` are removed in favor of more flexible api.
15-
- For adding GitHub link with icon to the nav, use [Social Links](./theme-nav.html#navigation-links) feature.
15+
- For adding GitHub link with icon to the nav, use [Social Links](./theme-nav#navigation-links) feature.
1616
- For adding "Edit this page" feature, use [Edit Link](./theme-edit-link) feature.
1717
- `lastUpdated` option is now split into `config.lastUpdated` and `themeConfig.lastUpdatedText`.
1818
- `carbonAds.carbon` is changed to `carbonAds.code`.

docs/guide/migration-from-vuepress.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Images
66

7-
Unlike VuePress, VitePress handles [`base`](/guide/asset-handling.html#base-url) of your config automatically when you use static image.
7+
Unlike VuePress, VitePress handles [`base`](./asset-handling#base-url) of your config automatically when you use static image.
88

99
Hence, now you can render images without `img` tag.
1010

@@ -14,7 +14,7 @@ Hence, now you can render images without `img` tag.
1414
```
1515

1616
::: warning
17-
For dynamic images you still need `withBase` as shown in [Base URL guide](/guide/asset-handling.html#base-url).
17+
For dynamic images you still need `withBase` as shown in [Base URL guide](./asset-handling#base-url).
1818
:::
1919

2020
Use `<img.*withBase\('(.*)'\).*alt="([^"]*)".*>` regex to find and replace it with `![$2]($1)` to replace all the images with `![](...)` syntax.

docs/guide/theme-introduction.md

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface Theme {
3838
Layout: Component // Vue 3 component
3939
NotFound?: Component
4040
enhanceApp?: (ctx: EnhanceAppContext) => void
41+
setup?: () => void
4142
}
4243

4344
interface EnhanceAppContext {
@@ -65,6 +66,11 @@ export default {
6566
// router is VitePress' custom router. `siteData` is
6667
// a `ref` of current site-level metadata.
6768
}
69+
70+
setup() {
71+
// this function will be executed inside VitePressApp's
72+
// setup hook. all composition APIs are available here.
73+
}
6874
}
6975
```
7076

docs/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"private": true,
3-
"name": "vitepress-docs"
3+
"devDependencies": {
4+
"vitepress": "workspace:*"
5+
}
46
}

examples/configured/.vitepress/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from '../../../src/node'
1+
import { defineConfig } from 'vitepress'
22

33
export default defineConfig({
44
title: 'Configured Example',

0 commit comments

Comments
 (0)