自定义配置
本指南介绍如何根据你的特定需求自定义 NextShip。
主题
配色方案
主题颜色在 src/config/themes.ts 中配置:
export const theme = {
// 选择预设:blue, green, purple, orange, rose, teal, zinc
primary: presets.green,
// 圆角大小:sm, md, lg, xl
radius: "lg",
// 启用深色模式切换
enableDarkMode: true,
};可用预设
| 预设 | 浅色 | 深色 |
|---|---|---|
| blue | oklch(0.546 0.245 262) | oklch(0.623 0.214 259) |
| green | oklch(0.527 0.154 150) | oklch(0.627 0.194 149) |
| purple | oklch(0.553 0.235 303) | oklch(0.627 0.265 303) |
| orange | oklch(0.705 0.213 47) | oklch(0.705 0.213 47) |
| rose | oklch(0.645 0.246 16) | oklch(0.645 0.246 16) |
自定义颜色
在 src/app/globals.css 中添加自定义颜色:
:root {
--primary-light: oklch(0.5 0.2 250);
--primary-dark: oklch(0.6 0.2 250);
}站点配置
更新 src/config/site.ts:
export const siteConfig = {
name: "Your SaaS",
description: "Your SaaS description",
url: process.env.NEXT_PUBLIC_APP_URL,
links: {
twitter: "https://twitter.com/yourhandle",
github: "https://github.com/yourrepo",
},
};订阅计划
在 src/config/plans.ts 中修改计划:
export const plans = {
starter: {
name: "Starter",
price: { monthly: 9, yearly: 90 },
stripePriceId: {
monthly: "price_xxx",
yearly: "price_yyy",
},
limits: {
projects: 5,
storage: "1GB",
},
features: [
"5 projects",
"1GB storage",
"Email support",
],
},
// 添加更多计划...
};国际化
添加新语言
- 在
src/i18n/config.ts中添加语言:
export const locales = ["en", "zh", "es"] as const;
export const localeNames = {
en: "English",
zh: "中文",
es: "Español",
};- 创建翻译文件
src/messages/es.json:
{
"common": {
"signIn": "Iniciar sesión",
"signUp": "Registrarse"
}
}使用翻译
import { useTranslations } from "next-intl";
function Component() {
const t = useTranslations("common");
return <button>{t("signIn")}</button>;
}添加组件
使用 shadcn/ui CLI
npx shadcn@latest add button
npx shadcn@latest add card
npx shadcn@latest add dialog组件会添加到 src/components/ui/。
创建自定义组件
// src/components/shared/feature-card.tsx
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
interface FeatureCardProps {
icon: React.ReactNode;
title: string;
description: string;
}
export function FeatureCard({ icon, title, description }: FeatureCardProps) {
return (
<Card>
<CardHeader>
<div className="mb-2 text-primary">{icon}</div>
<CardTitle>{title}</CardTitle>
</CardHeader>
<CardContent>
<p className="text-muted-foreground">{description}</p>
</CardContent>
</Card>
);
}扩展数据库
添加表
- 在
src/lib/db/schema.ts中定义:
export const products = pgTable("products", {
id: text("id").primaryKey(),
name: text("name").notNull(),
price: integer("price").notNull(),
createdAt: timestamp("created_at").defaultNow(),
});- 推送更改:
pnpm db:push添加 API 路由
在 src/server/trpc/routers/ 中创建 tRPC 路由:
// src/server/trpc/routers/product.ts
export const productRouter = createTRPCRouter({
list: publicProcedure.query(({ ctx }) => {
return ctx.db.select().from(products);
}),
});移除功能
移除 Stripe
- 删除
src/app/api/stripe/ - 移除账单组件
- 移除 Stripe 环境变量
- 卸载:
pnpm remove stripe @stripe/stripe-js
移除国际化
- 从路由结构中移除
[locale] - 删除
src/i18n/和src/messages/ - 移除
next-intl配置 - 卸载:
pnpm remove next-intl
最佳实践
- 将站点配置保存在
src/config/ - 使用环境变量存储密钥
- 在
src/components/shared/中创建可复用组件 - 在你自己的 README 中记录自定义内容