一个基于 Svelte 5 和 Tailwind CSS 4 构建的现代化移动端电商应用,展示了最新的 Web 技术栈和最佳实践。
clone-apps-apple/
├── src/
│ ├── lib/
│ │ ├── components/ # 可复用组件
│ │ │ ├── Header.svelte
│ │ │ ├── BottomNav.svelte
│ │ │ └── ProductCard.svelte
│ │ ├── stores/ # 全局状态管理
│ │ │ └── cart.svelte.ts
│ │ ├── data/ # 模拟数据
│ │ │ └── products.ts
│ │ └── types/ # TypeScript 类型定义
│ │ └── index.ts
│ └── routes/ # 页面路由
│ ├── +page.svelte # 首页
│ ├── search/ # 搜索页
│ ├── cart/ # 购物车
│ ├── profile/ # 个人中心
│ └── product/[id]/ # 商品详情
├── static/ # 静态资源
├── package.json
├── svelte.config.js
├── tailwind.config.js
└── vite.config.ts
# 使用 pnpm
pnpm install
# 或使用 npm
npm install
# 或使用 yarn
yarn install
# 启动开发服务器
pnpm dev
# 或
npm run dev
访问 http://localhost:5173 查看应用。
📱 建议使用浏览器的移动端模拟器查看效果:
# 构建
pnpm build
# 预览构建结果
pnpm preview
使用 Svelte 5 的 $state Rune 实现全局购物车状态:
class CartStore {
items = $state<CartItem[]>([]);
get count(): number {
return this.items.reduce((sum, item) => sum + item.quantity, 0);
}
add(product: Product): void {
// ...
}
}
export const cart = new CartStore();
使用 $derived 自动计算派生状态:
const filteredProducts = $derived(
selectedCategory === 'all' ? products : products.filter((p) => p.category === selectedCategory)
);
使用 SvelteKit 的文件系统路由:
/ - 首页/product/[id] - 动态商品详情页/search - 搜索页/cart - 购物车/profile - 个人中心使用 Svelte 内置的 transition 系统:
<div in:fly={{ y: 20, duration: 300 }} out:fade>
<!-- 内容 -->
</div>
$state$derived{#key} 块优化列表渲染项目使用 Tailwind CSS 4,配置文件位于 @tailwindcss/vite 插件中。
自定义颜色:
orange-500: #f97316)pink-500: #ec4899)启用了严格模式,确保类型安全:
{
"compilerOptions": {
"strict": true,
"moduleResolution": "bundler"
}
}
欢迎提交 Issue 和 Pull Request!
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)MIT License
如有任何问题或建议,欢迎通过以下方式联系:
⭐ 如果这个项目对你有帮助,请给个 Star 支持一下!