<!-- Generated from zh/llms-txt-remix/index.html. The canonical document is the HTML page. -->

- [ 首页 ](/zh/) 
/
- [ 如何创建 ](/zh/how-to-create/) 
/
- Remix 指南            
# Remix 的 `llms.txt`

Remix 有两种方法：在 public/ 中放置一个零配置静态文件，或在 app/routes/llms[.]txt.ts 创建资源路由，返回纯文本 Response，也可选择根据你的内容生成。

最近更新: 2026年4月22日

本页内容

- [ public/ 中的选项 1：静态文件 ](#static)
- [ 选项 2：资源路由 ](#resource-route)
- [ Vite 插件方式 ](#vite-plugin)
- [ 验证 ](#verify)              
备注

应使用哪种方案？

使用  静态文件  ，如果您的  llms.txt  很少变化，而且无需根据内容生成。请使用
资源路由  
用于动态生成，尤其当你的文档存储在数据库中或由 MDX 文件生成时。

## public/ 中的选项 1：静态文件

Remix 会将 `public/` 以静态方式放在站点根目录。 将文件放在 `public/llms.txt`，无需路由配置。
public/llms.txt, directory structure    复制     

```
# Remix static file approach
#
# Place your file at: public/llms.txt
# Remix (and the underlying Node/Cloudflare/Vercel adapter)
# serves everything in public/ at the root of your site.
#
# Project structure:
# your-remix-app/
# ├── public/
# │   └── llms.txt   ← add this
# ├── app/
# └── remix.config.js (or vite.config.ts)

```

此方法适用于所有 Remix 适配器： **@remix-run/node**, **@remix-run/cloudflare**, **@remix-run/vercel**，以及 **@remix-run/netlify**。静态文件优先于任何匹配的路由。

## 选项 2：资源路由

在以下位置创建资源路由： `app/routes/llms[.]txt.ts`。该 `[.]` 语法会转义文件名中的点，使 Remix 将其映射到 URL 路径 `/llms.txt`。导出一个 `loader` 函数，该函数返回一个 `Response` 并设置正确的 `Content-Type`.
app/routes/llms[.]txt.ts    复制     

```
// app/routes/llms[.]txt.ts
// Remix resource route, the [.] escapes the dot in the filename
// This file is served at exactly /llms.txt
import type { LoaderFunctionArgs } from '@remix-run/node';

export async function loader({ request }: LoaderFunctionArgs) {
const content = `# Your Site

> One-sentence description of what your site or product does.

## Documentation

- [Getting Started](https://yoursite.com/docs/start): Install and configure.
- [API Reference](https://yoursite.com/docs/api): Full endpoint catalog.

## Product

- [Overview](https://yoursite.com/product): Features and capabilities.
- [Pricing](https://yoursite.com/pricing): Plans and billing.

## Optional

- [Changelog](https://yoursite.com/changelog): Release history.
- [GitHub](https://github.com/your-org/your-repo): Source code.
`;

return new Response(content, {
status: 200,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
}

```

示例

使用 Web Response，不要用 json()

Remix 的  json()  辅助函数会设置  Content-Type: application/json 用于  llms.txt  你必须使用  new Response(body, { headers: { 'Content-Type': 'text/plain; charset=utf-8' }
})  
直接返回。

若要从内容层动态生成，请在加载器中获取文档，并以编程方式构建 Markdown 链接列表：
app/routes/llms[.]txt.ts, dynamic    复制     

```
// app/routes/llms[.]txt.ts
// Generate from your content / MDX files
import type { LoaderFunctionArgs } from '@remix-run/node';
import { getAllDocs } from '~/models/docs.server';

export async function loader({ request }: LoaderFunctionArgs) {
// Fetch your documentation index from a DB or file system
const docs = await getAllDocs();

const links = docs
.map((doc) => `- [${doc.title}](https://yoursite.com/docs/${doc.slug}/): ${doc.summary}`)
.join('\n');

const body = [
'# Your Site',
'',
'> One-sentence summary of your project.',
'',
'## Documentation',
'',
links,
].join('\n');

return new Response(body, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
}

```

## Vite 插件方式

如果您使用采用 Vite 的 Remix（Remix v2.7+ 的默认设置），可以生成 `llms.txt` ，在构建过程中通过 Vite 插件生成。生成的文件会放入构建输出目录，并作为静态资源提供，这兼具静态文件的简洁性和构建时访问内容的能力。
vite.config.ts, generate llms.txt at build    复制     

```
import { vitePlugin as remix } from '@remix-run/dev';
import { defineConfig } from 'vite';
import { writeFileSync } from 'node:fs';
import { resolve } from 'node:path';

// Simple Vite plugin to generate llms.txt at build time
function llmsTxtPlugin() {
return {
name: 'generate-llms-txt',
buildStart() {
const content = `# Your Site\n\n> Summary.\n\n## Documentation\n\n- [Docs](https://yoursite.com/docs): Guide.\n`;
writeFileSync(resolve(__dirname, 'public/llms.txt'), content, 'utf-8');
},
};
}

export default defineConfig({
plugins: [remix(), llmsTxtPlugin()],
});
```

## 验证

部署后，确认文件已正确提供：
Verification    复制     

```
curl -I https://yoursite.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8

curl https://yoursite.com/llms.txt | head -5
```

## 相关指南

- [如何创建 llms.txt](/zh/how-to-create/)、模板和检查清单。 
- [llms.txt 格式参考](/zh/llms-txt-format/)，规范细节。 
- [Vercel 指南](/zh/llms-txt-vercel/)，将 Remix 部署到 Vercel。 
- [Cloudflare Pages 指南](/zh/llms-txt-cloudflare/)，在 Cloudflare 上运行 Remix。 
- [验证器](/zh/validator/) · [生成器](/zh/generator/).        
## 来源

- [ llmstxt.org，社区提案 ](https://llmstxt.org/)
- [ Remix 文档，资源路由 ](https://v2.remix.run/docs/guides/resource-routes/)
- [ Remix 文档，文件约定 ](https://v2.remix.run/docs/file-conventions/routes/)
