Skip to content

部署参数怎么填:Build Command 和 Output Directory

部署平台经常会让你填写:

  • Build Command
  • Output Directory
  • Root Directory

这几个值填错,最常见的问题就是部署失败、页面空白、样式丢失。

一、先看 package.json

在项目根目录打开 package.json

找到 scripts

json
{
  "scripts": {
    "dev": "vitepress dev docs",
    "build": "vitepress build docs",
    "preview": "vitepress preview docs"
  }
}

这里说明:

命令作用
npm run dev本地开发
npm run build构建发布文件
npm run preview本地预览构建结果

所以部署平台的 Build Command 通常填:

text
npm run build

二、确认输出目录

先在本地运行:

bash
npm run build

构建成功后,VitePress 通常会生成:

text
docs/.vitepress/dist

所以 Output Directory 填:

text
docs/.vitepress/dist

三、Root Directory 是什么

Root Directory 是部署平台从哪个文件夹开始执行命令。

如果 package.json 在仓库根目录,Root Directory 通常留空或填仓库根目录。

如果你的项目结构是:

text
my-repo/
  package.json
  docs/

那么:

配置项推荐值
Root Directory留空
Build Commandnpm run build
Output Directorydocs/.vitepress/dist

如果你的项目结构是:

text
my-repo/
  docs/
    package.json

那么 Root Directory 可能要填:

text
docs

输出目录也可能变成:

text
.vitepress/dist

四、Vercel 常见填写

当前这种 VitePress 项目通常可以这样填:

配置项
Framework PresetOther
Build Commandnpm run build
Output Directorydocs/.vitepress/dist
Install Commandnpm install 或默认

如果平台自动识别不准,就手动填。

五、GitHub Pages 额外注意 base

如果你的 GitHub Pages 地址带仓库名,例如:

text
https://你的用户名.github.io/my-docs/

VitePress 通常需要:

ts
export default defineConfig({
  base: '/my-docs/',
})

如果你绑定了自定义域名,例如:

text
https://docs.example.com/

通常不需要仓库名形式的 base

六、部署失败时怎么问 AI

text
请帮我检查部署配置。

项目信息:
1. package.json scripts 内容如下:
粘贴 scripts

2. 部署平台填写:
Root Directory:
Build Command:
Output Directory:

3. 构建日志报错:
粘贴完整日志

请判断这些参数是否正确,并给出最小修改建议。

注意

不要只看别人教程里的 Output Directory。不同项目结构不一样,最可靠的方法是本地运行构建命令,看实际生成了哪个目录。

基于 VitePress 构建