Skip to content

Commit

Permalink
docs: add vitepress-plugin-group-icons (#18132)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyinws committed Sep 19, 2024
1 parent 52dff2b commit b529b6f
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 69 deletions.
17 changes: 17 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { DefaultTheme } from 'vitepress'
import { defineConfig } from 'vitepress'
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
import {
groupIconMdPlugin,
groupIconVitePlugin,
} from 'vitepress-plugin-group-icons'
import { buildEnd } from './buildEnd.config'

const ogDescription = 'Next Generation Frontend Tooling'
Expand Down Expand Up @@ -394,6 +398,19 @@ export default defineConfig({
},
markdown: {
codeTransformers: [transformerTwoslash()],
config(md) {
md.use(groupIconMdPlugin)
},
},
vite: {
plugins: [
groupIconVitePlugin({
customIcon: {
firebase: 'vscode-icons:file-type-firebase',
'.gitlab-ci.yml': 'vscode-icons:file-type-gitlab',
},
}),
],
},
buildEnd,
})
1 change: 1 addition & 0 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import './styles/vars.css'
import HomeSponsors from './components/HomeSponsors.vue'
import AsideSponsors from './components/AsideSponsors.vue'
import SvgImage from './components/SvgImage.vue'
import 'virtual:group-icons.css'

export default {
extends: DefaultTheme,
Expand Down
3 changes: 1 addition & 2 deletions docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ The first case is when `localhost` is used. Node.js under v17 reorders the resul

You can set [`dns.setDefaultResultOrder('verbatim')`](https://nodejs.org/api/dns.html#dns_dns_setdefaultresultorder_order) to disable the reordering behavior. Vite will then print the address as `localhost`.

```js twoslash
// vite.config.js
```js twoslash [vite.config.js]
import { defineConfig } from 'vite'
import dns from 'node:dns'

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/api-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async function build(

**Example Usage:**

```ts twoslash
```ts twoslash [vite.config.js]
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { build } from 'vite'
Expand Down
18 changes: 6 additions & 12 deletions docs/guide/api-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ See also [Virtual Modules Convention](#virtual-modules-convention).

Users will add plugins to the project `devDependencies` and configure them using the `plugins` array option.

```js
// vite.config.js
```js [vite.config.js]
import vitePlugin from 'vite-plugin-feature'
import rollupPlugin from 'rollup-plugin-feature'

Expand All @@ -66,8 +65,7 @@ export default function framework(config) {
}
```

```js
// vite.config.js
```js [vite.config.js]
import { defineConfig } from 'vite'
import framework from 'vite-plugin-framework'

Expand Down Expand Up @@ -519,8 +517,7 @@ If a Rollup plugin only makes sense for the build phase, then it can be specifie
You can also augment an existing Rollup plugin with Vite-only properties:
```js
// vite.config.js
```js [vite.config.js]
import example from 'rollup-plugin-example'
import { defineConfig } from 'vite'
Expand Down Expand Up @@ -560,8 +557,7 @@ Since Vite 2.9, we provide some utilities for plugins to help handle the communi

On the plugin side, we could use `server.ws.send` to broadcast events to the client:

```js
// vite.config.js
```js [vite.config.js]
export default defineConfig({
plugins: [
{
Expand Down Expand Up @@ -606,8 +602,7 @@ if (import.meta.hot) {

Then use `server.ws.on` and listen to the events on the server side:

```js
// vite.config.js
```js [vite.config.js]
export default defineConfig({
plugins: [
{
Expand All @@ -632,8 +627,7 @@ Internally, vite infers the type of a payload from the `CustomEventMap` interfac
Make sure to include the `.d.ts` extension when specifying TypeScript declaration files. Otherwise, Typescript may not know which file the module is trying to extend.
:::

```ts
// events.d.ts
```ts [events.d.ts]
import 'vite/types/customEvent.d.ts'
declare module 'vite/types/customEvent.d.ts' {
Expand Down
5 changes: 2 additions & 3 deletions docs/guide/backend-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ If you need a custom integration, you can follow the steps in this guide to conf

1. In your Vite config, configure the entry and enable build manifest:

```js twoslash
```js twoslash [vite.config.js]
import { defineConfig } from 'vite'
// ---cut---
// vite.config.js
export default defineConfig({
build: {
// generate .vite/manifest.json in outDir
Expand Down Expand Up @@ -60,7 +59,7 @@ If you need a custom integration, you can follow the steps in this guide to conf

3. For production: after running `vite build`, a `.vite/manifest.json` file will be generated alongside other asset files. An example manifest file looks like this:

```json
```json [.vite/manifest.json]
{
"_shared-!~{003}~.js": {
"file": "assets/shared-ChJ_j-JJ.css",
Expand Down
18 changes: 7 additions & 11 deletions docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ For advanced base path control, check out [Advanced Base Options](#advanced-base

The build can be customized via various [build config options](/config/build-options.md). Specifically, you can directly adjust the underlying [Rollup options](https://rollupjs.org/configuration-options/) via `build.rollupOptions`:

```js
```js [vite.config.js]
export default defineConfig({
build: {
rollupOptions: {
Expand Down Expand Up @@ -65,8 +65,7 @@ When a new deployment occurs, the hosting service may delete the assets from pre

You can enable rollup watcher with `vite build --watch`. Or, you can directly adjust the underlying [`WatcherOptions`](https://rollupjs.org/configuration-options/#watch) via `build.watch`:

```js
// vite.config.js
```js [vite.config.js]
export default defineConfig({
build: {
watch: {
Expand Down Expand Up @@ -96,8 +95,7 @@ During dev, simply navigate or link to `/nested/` - it works as expected, just l

During build, all you need to do is to specify multiple `.html` files as entry points:

```js twoslash
// vite.config.js
```js twoslash [vite.config.js]
import { resolve } from 'path'
import { defineConfig } from 'vite'

Expand All @@ -123,8 +121,7 @@ When you are developing a browser-oriented library, you are likely spending most

When it is time to bundle your library for distribution, use the [`build.lib` config option](/config/build-options.md#build-lib). Make sure to also externalize any dependencies that you do not want to bundle into your library, e.g. `vue` or `react`:

```js twoslash
// vite.config.js
```js twoslash [vite.config.js]
import { resolve } from 'path'
import { defineConfig } from 'vite'

Expand Down Expand Up @@ -155,8 +152,7 @@ export default defineConfig({

The entry file would contain exports that can be imported by users of your package:

```js
// lib/main.js
```js [lib/main.js]
import Foo from './Foo.vue'
import Bar from './Bar.vue'
export { Foo, Bar }
Expand All @@ -173,7 +169,7 @@ dist/my-lib.umd.cjs 0.30 kB / gzip: 0.16 kB

Recommended `package.json` for your lib:

```json
```json [package.json]
{
"name": "my-lib",
"type": "module",
Expand All @@ -191,7 +187,7 @@ Recommended `package.json` for your lib:

Or, if exposing multiple entry points:

```json
```json [package.json]
{
"name": "my-lib",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/dep-pre-bundling.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ In a monorepo setup, a dependency may be a linked package from the same repo. Vi
However, this requires the linked dep to be exported as ESM. If not, you can add the dependency to [`optimizeDeps.include`](/config/dep-optimization-options.md#optimizedeps-include) and [`build.commonjsOptions.include`](/config/build-options.md#build-commonjsoptions) in your config.
```js twoslash
```js twoslash [vite.config.js]
import { defineConfig } from 'vite'
// ---cut---
export default defineConfig({
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/env-and-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Loaded env variables are also exposed to your client source code via `import.met

To prevent accidentally leaking env variables to the client, only variables prefixed with `VITE_` are exposed to your Vite-processed code. e.g. for the following env variables:

```
```[.env]
VITE_SOME_KEY=123
DB_PASSWORD=foobar
```
Expand All @@ -59,7 +59,7 @@ Also, Vite uses [dotenv-expand](https://github.com/motdotla/dotenv-expand) to ex
Note that if you want to use `$` inside your environment value, you have to escape it with `\`.
```
```[.env]
KEY=123
NEW_KEY1=test$foo # test
NEW_KEY2=test\$foo # test$foo
Expand All @@ -81,7 +81,7 @@ By default, Vite provides type definitions for `import.meta.env` in [`vite/clien
To achieve this, you can create an `vite-env.d.ts` in `src` directory, then augment `ImportMetaEnv` like this:
```typescript
```typescript [vite-env.d.ts]
/// <reference types="vite/client" />

interface ImportMetaEnv {
Expand All @@ -96,7 +96,7 @@ interface ImportMeta {
If your code relies on types from browser environments such as [DOM](https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts) and [WebWorker](https://github.com/microsoft/TypeScript/blob/main/src/lib/webworker.generated.d.ts), you can update the [lib](https://www.typescriptlang.org/tsconfig#lib) field in `tsconfig.json`.
```json
```json [tsconfig.json]
{
"lib": ["WebWorker"]
}
Expand Down
11 changes: 4 additions & 7 deletions docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Vite's default types are for its Node.js API. To shim the environment of client

Alternatively, you can add `vite/client` to `compilerOptions.types` inside `tsconfig.json`:

```json
```json [tsconfig.json]
{
"compilerOptions": {
"types": ["vite/client"]
Expand Down Expand Up @@ -176,8 +176,7 @@ Vue users should use the official [@vitejs/plugin-vue-jsx](https://github.com/vi

If using JSX without React or Vue, custom `jsxFactory` and `jsxFragment` can be configured using the [`esbuild` option](/config/shared-options.md#esbuild). For example for Preact:

```js twoslash
// vite.config.js
```js twoslash [vite.config.js]
import { defineConfig } from 'vite'

export default defineConfig({
Expand All @@ -192,8 +191,7 @@ More details in [esbuild docs](https://esbuild.github.io/content-types/#jsx).

You can inject the JSX helpers using `jsxInject` (which is a Vite-only option) to avoid manual imports:

```js twoslash
// vite.config.js
```js twoslash [vite.config.js]
import { defineConfig } from 'vite'

export default defineConfig({
Expand Down Expand Up @@ -223,8 +221,7 @@ Note that CSS minification will run after PostCSS and will use [`build.cssTarget

Any CSS file ending with `.module.css` is considered a [CSS modules file](https://github.com/css-modules/css-modules). Importing such a file will return the corresponding module object:

```css
/* example.module.css */
```css [example.module.css]
.red {
color: red;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Note that Vite will also resolve [its config file (i.e. `vite.config.js`)](/conf
In a project where Vite is installed, you can use the `vite` binary in your npm scripts, or run it directly with `npx vite`. Here are the default npm scripts in a scaffolded Vite project:

<!-- prettier-ignore -->
```json
```json [package.json]
{
"scripts": {
"dev": "vite", // start dev server, aliases: `vite dev`, `vite serve`
Expand Down
5 changes: 2 additions & 3 deletions docs/guide/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ If you are using TypeScript, enable `"moduleResolution": "bundler"` and `"allowI

Barrel files are files that re-export the APIs of other files in the same directory. For example:

```js
// src/utils/index.js
```js [src/utils/index.js]
export * from './color.js'
export * from './dom.js'
export * from './slash.js'
Expand Down Expand Up @@ -92,7 +91,7 @@ vite:transform 62.95ms /src/components/BigComponent.vue +1ms
vite:transform 102.54ms /src/utils/big-utils.js +1ms
```

```js
```js [vite.config.js]
export default defineConfig({
server: {
warmup: {
Expand Down
15 changes: 6 additions & 9 deletions docs/guide/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ A typical SSR application will have the following source file structure:

The `index.html` will need to reference `entry-client.js` and include a placeholder where the server-rendered markup should be injected:

```html
```html [index.html]
<div id="app"><!--ssr-outlet--></div>
<script type="module" src="/src/entry-client.js"></script>
```
Expand All @@ -69,9 +69,7 @@ This is statically replaced during build so it will allow tree-shaking of unused
When building an SSR app, you likely want to have full control over your main server and decouple Vite from the production environment. It is therefore recommended to use Vite in middleware mode. Here is an example with [express](https://expressjs.com/):
**server.js**
```js{15-18} twoslash
```js{15-18} twoslash [server.js]
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
Expand Down Expand Up @@ -113,7 +111,7 @@ Here `vite` is an instance of [ViteDevServer](./api-javascript#vitedevserver). `
The next step is implementing the `*` handler to serve server-rendered HTML:
```js twoslash
```js twoslash [server.js]
// @noErrors
import fs from 'node:fs'
import path from 'node:path'
Expand Down Expand Up @@ -166,7 +164,7 @@ app.use('*', async (req, res, next) => {
The `dev` script in `package.json` should also be changed to use the server script instead:
```diff
```diff [package.json]
"scripts": {
- "dev": "vite"
+ "dev": "node server"
Expand All @@ -182,7 +180,7 @@ To ship an SSR project for production, we need to:
Our scripts in `package.json` will look like this:
```json
```json [package.json]
{
"scripts": {
"dev": "node server",
Expand Down Expand Up @@ -219,8 +217,7 @@ To leverage the manifest, frameworks need to provide a way to collect the module
`@vitejs/plugin-vue` supports this out of the box and automatically registers used component module IDs on to the associated Vue SSR context:
```js
// src/entry-server.js
```js [src/entry-server.js]
const ctx = {}
const html = await vueServerRenderer.renderToString(app, ctx)
// ctx.modules is now a Set of module IDs that were used during the render
Expand Down
Loading

0 comments on commit b529b6f

Please sign in to comment.