Skip to content
1 change: 1 addition & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default defineConfig({
title: 'Vite 官方中文文档',
description: '下一代前端工具链',
lang: 'zh-CN',
cleanUrls: true,

head: [
['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }],
Expand Down
23 changes: 3 additions & 20 deletions config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,11 @@ export default defineConfig({

- **类型:** `boolean | { fileName?: string }`
- **默认:** `false`
- **相关:** [许可证](/guide/features#license)

当设置为 `true` 时,构建过程将生成一个 `.vite/license.md` 文件,其中包含所有打包依赖项的许可证信息。该文件可以被托管,用于展示和确认应用程序所使用的依赖项。当传入 `fileName` 参数时,它将被用作相对于 `outDir` 的许可证文件名。示例输出可能如下所示:
当设置为 `true` 时,构建过程将生成一个 `.vite/license.md` 文件,其中包含所有打包依赖项的许可证信息。

```md
# Licenses

The app bundles dependencies which contain the following licenses:

## dep-1 - 1.2.3 (CC0-1.0)

CC0 1.0 Universal

...

## dep-2 - 4.5.6 (MIT)

MIT License

...
```

如果 `fileName` 以 `.json` 结尾,则会生成原始的 JSON 元数据,可用于进一步处理。例如:
如果传入了 `fileName` 参数,它将被用作相对于 `outDir` 的许可证文件名。如果文件名以 `.json` 结尾,则会生成原始的 JSON 元数据,并可以用于进一步处理。例如:

```json
[
Expand Down
36 changes: 36 additions & 0 deletions guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,42 @@ import MyWorker from './worker?worker&url'
不要为 [`script-src`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src) 允许 `data:`。这将会允许注入任何脚本。
:::

## License

Vite 可以通过 [`build.license`](/config/build-options.md#build-license) 选项生成一个包含构建中使用的所有依赖项许可证的文件。该文件可以被托管,用于显示和确认应用程序所使用的依赖项。

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

export default defineConfig({
build: {
license: true,
},
})
```

这将生成一个 `.vite/license.md` 文件,其输出内容可能如下所示:

```md
# Licenses

The app bundles dependencies which contain the following licenses:

## dep-1 - 1.2.3 (CC0-1.0)

CC0 1.0 Universal

...

## dep-2 - 4.5.6 (MIT)

MIT License

...
```

要将文件服务于不同的路径,你可以传递 `{ fileName: 'license.md' }` 作为示例,这样它就会在 `https://example.com/license.md` 路径下提供服务。有关更多信息,请参见 [`build.license`](/config/build-options.md#build-license) 文档。

## 构建优化 {#build-optimizations}

> 下面所罗列的功能会自动应用为构建过程的一部分,除非你想禁用它们,否则没有必要显式配置。
Expand Down
16 changes: 14 additions & 2 deletions guide/static-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,25 @@ $ npm run preview

## GitHub Pages {#github-pages}

1. 在 `vite.config.js` 中设置正确的 `base`。
1. **更新 Vite 配置**

在 `vite.config.js` 中设置正确的 `base`。

如果你正要部署到 `https://<USERNAME>.github.io/`,或者通过 GitHub Pages 部署到一个自定义域名(例如 `www.example.com`),请将 `base` 设置为 `'/'`。或者,你也可以从配置中移除 `base`,因为它默认为 `'/'`。

如果你正在部署到 `https://<USERNAME>.github.io/<REPO>/`(例如你的仓库地址为 `https://github.com/<USERNAME>/<REPO>`),那么请将 `base` 设置为 `'/<REPO>/'`。

2. 进入仓库 settings 页面的 GitHub Pages 配置,选择部署来源为“GitHub Actions”,这将引导你创建一个构建和部署项目的工作流程,我们提供了一个安装依赖项和使用 npm 构建的工作流程样本:
2. **启用 GitHub Pages**

在你的仓库中,进入 **Settings → Pages**。在 **Build and deployment** 下,打开 **Source** 下拉菜单,然后选择 **GitHub Actions**。

GitHub 现在将使用 GitHub Actions [工作流](https://docs.github.com/en/actions/concepts/workflows-and-actions/workflows)来部署你的网站,这是必要的,因为 Vite 需要构建步骤来进行部署。

3. **创建工作流**

在你的仓库中创建一个新文件 `.github/workflows/deploy.yml`。你也可以从上一步点击 **"create your own"**,这将为你生成一个起始工作流程文件。

这里有一个示例工作流程,它使用 npm 安装依赖项,构建网站,并在你向 `main` 分支推送更改时部署它:

<<< ./static-deploy-github-pages.yaml#content [.github/workflows/deploy.yml]

Expand Down