|
| 1 | +--- |
| 2 | +layout: doc |
| 3 | +--- |
| 4 | + |
| 5 | +# Getting Started |
| 6 | + |
| 7 | +## Try It Online |
| 8 | + |
| 9 | +You can try VitePress directly in your browser on [StackBlitz](https://vitepress.new). |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +### Prerequisites |
| 14 | + |
| 15 | +- [Node.js](https://nodejs.org/) version 18 or higher. |
| 16 | +- Terminal for accessing VitePress via its command line interface (CLI). |
| 17 | +- Text Editor with [Markdown](https://en.wikipedia.org/wiki/Markdown) syntax support. |
| 18 | + - [VSCode](https://code.visualstudio.com/) is recommended, along with the [official Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar). |
| 19 | + |
| 20 | +VitePress can be used on its own, or be installed into an existing project. In both cases, you can install it with: |
| 21 | + |
| 22 | +::: code-group |
| 23 | + |
| 24 | +```sh [npm] |
| 25 | +$ npm add -D vitepress@next |
| 26 | +``` |
| 27 | + |
| 28 | +```sh [pnpm] |
| 29 | +$ pnpm add -D vitepress@next |
| 30 | +``` |
| 31 | + |
| 32 | +```sh [yarn] |
| 33 | +$ yarn add -D vitepress@next vue |
| 34 | +``` |
| 35 | + |
| 36 | +```sh [bun] |
| 37 | +$ bun add -D vitepress@next |
| 38 | +``` |
| 39 | + |
| 40 | +::: |
| 41 | + |
| 42 | +::: tip NOTE |
| 43 | + |
| 44 | +VitePress is an ESM-only package. Don't use `require()` to import it, and make sure your nearest `package.json` contains `"type": "module"`, or change the file extension of your relevant files like `.vitepress/config.js` to `.mjs`/`.mts`. Refer to [Vite's troubleshooting guide](http://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only) for more details. Also, inside async CJS contexts, you can use `await import('vitepress')` instead. |
| 45 | + |
| 46 | +::: |
| 47 | + |
| 48 | +### Setup Wizard |
| 49 | + |
| 50 | +VitePress ships with a command line setup wizard that will help you scaffold a basic project. After installation, start the wizard by running: |
| 51 | + |
| 52 | +::: code-group |
| 53 | + |
| 54 | +```sh [npm] |
| 55 | +$ npx vitepress init |
| 56 | +``` |
| 57 | + |
| 58 | +```sh [pnpm] |
| 59 | +$ pnpm vitepress init |
| 60 | +``` |
| 61 | + |
| 62 | +```sh [yarn] |
| 63 | +$ yarn vitepress init |
| 64 | +``` |
| 65 | + |
| 66 | +```sh [bun] |
| 67 | +$ bun vitepress init |
| 68 | +``` |
| 69 | + |
| 70 | +[//]: # (:::) |
| 71 | + |
| 72 | +[//]: # () |
| 73 | +[//]: # (You will be greeted with a few simple questions:) |
| 74 | + |
| 75 | +[//]: # () |
| 76 | +[//]: # (<<< @/snippets/init.ansi) |
| 77 | + |
| 78 | +[//]: # () |
| 79 | +[//]: # (::: tip Vue as Peer Dependency) |
| 80 | + |
| 81 | +[//]: # (If you intend to perform customization that uses Vue components or APIs, you should also explicitly install `vue` as a dependency.) |
| 82 | + |
| 83 | +[//]: # (:::) |
| 84 | + |
| 85 | +## File Structure |
| 86 | + |
| 87 | +If you are building a standalone VitePress site, you can scaffold the site in your current directory (`./`). However, if you are installing VitePress in an existing project alongside other source code, it is recommended to scaffold the site in a nested directory (e.g. `./docs`) so that it is separate from the rest of the project. |
| 88 | + |
| 89 | +Assuming you chose to scaffold the VitePress project in `./docs`, the generated file structure should look like this: |
| 90 | + |
| 91 | +``` |
| 92 | +. |
| 93 | +├─ docs |
| 94 | +│ ├─ .vitepress |
| 95 | +│ │ └─ config.js |
| 96 | +│ ├─ api-examples.md |
| 97 | +│ ├─ markdown-examples.md |
| 98 | +│ └─ index.md |
| 99 | +└─ package.json |
| 100 | +``` |
| 101 | + |
| 102 | +The `docs` directory is considered the **project root** of the VitePress site. The `.vitepress` directory is a reserved location for VitePress' config file, dev server cache, build output, and optional theme customization code. |
| 103 | + |
| 104 | +::: tip |
| 105 | +By default, VitePress stores its dev server cache in `.vitepress/cache`, and the production build output in `.vitepress/dist`. If using Git, you should add them to your `.gitignore` file. These locations can also be [configured](../reference/site-config#outdir). |
| 106 | +::: |
| 107 | + |
| 108 | +### The Config File |
| 109 | + |
| 110 | +The config file (`.vitepress/config.js`) allows you to customize various aspects of your VitePress site, with the most basic options being the title and description of the site: |
| 111 | + |
| 112 | +```js [.vitepress/config.js] |
| 113 | +export default { |
| 114 | + // site-level options |
| 115 | + title: 'VitePress', |
| 116 | + description: 'Just playing around.', |
| 117 | + |
| 118 | + themeConfig: { |
| 119 | + // theme-level options |
| 120 | + } |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +You can also configure the behavior of the theme via the `themeConfig` option. Consult the [Config Reference](../reference/site-config) for full details on all config options. |
| 125 | + |
| 126 | +### Source Files |
| 127 | + |
| 128 | +Markdown files outside the `.vitepress` directory are considered **source files**. |
| 129 | + |
| 130 | +VitePress uses **file-based routing**: each `.md` file is compiled into a corresponding `.html` file with the same path. For example, `index.md` will be compiled into `index.html`, and can be visited at the root path `/` of the resulting VitePress site. |
| 131 | + |
| 132 | +VitePress also provides the ability to generate clean URLs, rewrite paths, and dynamically generate pages. These will be covered in the [Routing Guide](./routing). |
| 133 | + |
| 134 | +## Up and Running |
| 135 | + |
| 136 | +The tool should have also injected the following npm scripts to your `package.json` if you allowed it to do so during the setup process: |
| 137 | + |
| 138 | +```json [package.json] |
| 139 | +{ |
| 140 | + ... |
| 141 | + "scripts": { |
| 142 | + "docs:dev": "vitepress dev docs", |
| 143 | + "docs:build": "vitepress build docs", |
| 144 | + "docs:preview": "vitepress preview docs" |
| 145 | + }, |
| 146 | + ... |
| 147 | +} |
| 148 | +``` |
| 149 | + |
| 150 | +The `docs:dev` script will start a local dev server with instant hot updates. Run it with the following command: |
| 151 | + |
| 152 | +::: code-group |
| 153 | + |
| 154 | +```sh [npm] |
| 155 | +$ npm run docs:dev |
| 156 | +``` |
| 157 | + |
| 158 | +```sh [pnpm] |
| 159 | +$ pnpm run docs:dev |
| 160 | +``` |
| 161 | + |
| 162 | +```sh [yarn] |
| 163 | +$ yarn docs:dev |
| 164 | +``` |
| 165 | + |
| 166 | +```sh [bun] |
| 167 | +$ bun run docs:dev |
| 168 | +``` |
| 169 | + |
| 170 | +::: |
| 171 | + |
| 172 | +Instead of npm scripts, you can also invoke VitePress directly with: |
| 173 | + |
| 174 | +::: code-group |
| 175 | + |
| 176 | +```sh [npm] |
| 177 | +$ npx vitepress dev docs |
| 178 | +``` |
| 179 | + |
| 180 | +```sh [pnpm] |
| 181 | +$ pnpm vitepress dev docs |
| 182 | +``` |
| 183 | + |
| 184 | +```sh [yarn] |
| 185 | +$ yarn vitepress dev docs |
| 186 | +``` |
| 187 | + |
| 188 | +```sh [bun] |
| 189 | +$ bun vitepress dev docs |
| 190 | +``` |
| 191 | + |
| 192 | +::: |
| 193 | + |
| 194 | +More command line usage is documented in the [CLI Reference](../reference/cli). |
| 195 | + |
| 196 | +The dev server should be running at `http://localhost:5173`. Visit the URL in your browser to see your new site in action! |
| 197 | + |
| 198 | +## What's Next? |
| 199 | + |
| 200 | +- To better understand how markdown files are mapped to generated HTML, proceed to the [Routing Guide](./routing). |
| 201 | + |
| 202 | +- To discover more about what you can do on the page, such as writing markdown content or using Vue Components, refer to the "Writing" section of the guide. A great place to start would be to learn about [Markdown Extensions](./markdown). |
| 203 | + |
| 204 | +- To explore the features provided by the default documentation theme, check out the [Default Theme Config Reference](../reference/default-theme-config). |
| 205 | + |
| 206 | +- If you want to further customize the appearance of your site, explore how to either [Extend the Default Theme](./extending-default-theme) or [Build a Custom Theme](./custom-theme). |
| 207 | + |
| 208 | +- Once your documentation site takes shape, make sure to read the [Deployment Guide](./deploy). |
0 commit comments