v.Latest
Documentation
配置参考
在此页面上
从 tina/config.{ts,tsx,js,jsx} 导出的 defineConfig 函数的结果定义了你的 TinaCMS 设置。
重要 - 配置必须是确定性的
defineConfig 返回的对象在开发和构建过程中必须多次评估。避免在影响模式或运行时配置的配置属性中直接使用非确定性值(例如 Date.now(), Math.random())。这可能导致 GraphQL 模式不匹配错误。
如果需要动态值,请返回一个函数并延迟计算该值。
注意,它必须是默认导出。
配置文件的位置以前是在.tina/config.{ts,tsx,js,jsx}
选项
REQUIRED
schema
Schema
定义你的内容模型。
branch
string | null
用于拉取内容的基础分支。对于 TinaCloud 是必需的。
clientId
string | null
来自 TinaCloud 的 clientId。对于 TinaCloud 是必需的。
token
string | null
来自 TinaCloud 的只读令牌。对于 TinaCloud 是必需的。
localContentPath
string
本地开发中单独内容仓库的相对路径。
authProvider
AuthProvider
设置 自定义身份验证。
EXPERIMENTAL
contentApiUrlOverride
string
覆盖默认内容 API URL。
All properties marked as REQUIRED must be specified for the field to work properly.
示例
Vercel 和 TinaCloud 配置
这是一个使用 TinaCloud 托管数据层的标准配置,以及内置的 Tina 媒体和搜索功能。
const branch =process.env.NEXT_PUBLIC_TINA_BRANCH ||process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF ||process.env.HEAD ||'main';export default defineConfig({branch,// 由 TinaCloud 生成token: '<Your Read Only Token>',// 由 TinaCloud 生成clientId: '<Your Client ID>',build: {publicFolder: 'public',outputFolder: 'admin',},schema: {//内容模型定义在这里...},ui: {previewUrl: (context) => {// 基于分支名称使用 Vercel 预览部署return { url: `https://my-app-git-${context.branch}.vercel.app` };},},media: {tina: {publicFolder: 'public',mediaRoot: 'uploads',},},search: {tina: {indexerToken: process.env.TINA_SEARCH_TOKEN,},},});
Cloudinary 媒体存储
Tina 支持 Git 支持的媒体和特定的外部媒体提供商:
export default defineConfig({// ... 其他配置选项media: {loadCustomStore: async () => {const pack = await import('next-tinacms-cloudinary');return pack.TinaCloudCloudinaryMediaStore;},accept: 'image/*',},});
TinaCloud 搜索选项
Tina 通过 TinaCloud 提供内置的搜索功能。
// Tina Cloud 搜索export default defineConfig({// ... 其他配置选项search: {tina: {indexerToken: process.env.TINA_SEARCH_TOKEN,stopwordLanguages: ['eng', 'fra'],tokenSplitRegex: '/[p{L}d_]+/',},},});
使用 TypeScript 路径别名的导入
TinaCMS 支持在 tina/config.{ts,js,tsx} 文件和集合中使用 TypeScript 路径别名。
确保 tsconfig.json 存在于项目的根目录。在 compilerOptions 部分定义你的别名。
//tsconfig.json{"compilerOptions": {"baseUrl": ".","paths": {"@/*": ["src/*"]}}}
现在你可以使用别名导入实用程序或其他模块。
import { someUtility } from '@/lib/utils';export default defineConfig({//...});