@coze-arch/cli 0.0.1-alpha.afefde → 0.0.1-alpha.b287c1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +30 -21
- package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +2 -2
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +2 -2
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +46 -0
- package/lib/__templates__/expo/AGENTS.md +74 -0
- package/lib/__templates__/expo/README.md +0 -71
- package/lib/__templates__/expo/_npmrc +1 -0
- package/lib/__templates__/expo/client/app/+not-found.tsx +30 -0
- package/lib/__templates__/expo/client/app/_layout.tsx +15 -12
- package/lib/__templates__/expo/client/app/index.tsx +1 -1
- package/lib/__templates__/expo/client/app.config.ts +4 -3
- package/lib/__templates__/expo/client/components/Screen.tsx +3 -19
- package/lib/__templates__/expo/client/components/ThemedView.tsx +1 -2
- package/lib/__templates__/expo/client/constants/theme.ts +21 -698
- package/lib/__templates__/expo/client/declarations.d.ts +5 -0
- package/lib/__templates__/expo/client/eslint.config.mjs +40 -10
- package/lib/__templates__/expo/client/hooks/{useColorScheme.ts → useColorScheme.tsx} +20 -6
- package/lib/__templates__/expo/client/hooks/useSafeRouter.ts +152 -0
- package/lib/__templates__/expo/client/hooks/useTheme.ts +26 -6
- package/lib/__templates__/expo/client/metro.config.js +3 -0
- package/lib/__templates__/expo/client/package.json +36 -34
- package/lib/__templates__/expo/client/screens/{home → demo}/index.tsx +4 -4
- package/lib/__templates__/expo/client/scripts/install-missing-deps.js +11 -10
- package/lib/__templates__/expo/client/utils/index.ts +22 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/names.js +1889 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/rule.js +174 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/v5-only-names.js +388 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/rule.js +112 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/tech.md +94 -0
- package/lib/__templates__/expo/eslint-plugins/react-native/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/react-native/rule.js +64 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/rule.js +88 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/rule.js +120 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/tech.md +58 -0
- package/lib/__templates__/expo/package.json +3 -0
- package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +1318 -2636
- package/lib/__templates__/expo/server/build.js +21 -0
- package/lib/__templates__/expo/server/package.json +9 -7
- package/lib/__templates__/expo/server/src/index.ts +3 -1
- package/lib/__templates__/expo/template.config.js +56 -0
- package/lib/__templates__/native-static/.coze +11 -0
- package/lib/__templates__/native-static/index.html +33 -0
- package/lib/__templates__/native-static/styles/main.css +136 -0
- package/lib/__templates__/native-static/template.config.js +22 -0
- package/lib/__templates__/nextjs/.babelrc +15 -0
- package/lib/__templates__/nextjs/AGENTS.md +54 -0
- package/lib/__templates__/nextjs/README.md +5 -0
- package/lib/__templates__/nextjs/eslint.config.mjs +5 -0
- package/lib/__templates__/nextjs/next.config.ts +2 -3
- package/lib/__templates__/nextjs/package.json +8 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +3472 -1561
- package/lib/__templates__/nextjs/scripts/build.sh +4 -1
- package/lib/__templates__/nextjs/scripts/dev.sh +8 -2
- package/lib/__templates__/nextjs/scripts/start.sh +7 -1
- package/lib/__templates__/nextjs/src/app/layout.tsx +5 -3
- package/lib/__templates__/nextjs/src/app/page.tsx +17 -60
- package/lib/__templates__/nextjs/src/server.ts +35 -0
- package/lib/__templates__/nextjs/template.config.js +47 -12
- package/lib/__templates__/nextjs/tsconfig.json +1 -1
- package/lib/__templates__/nuxt-vue/.coze +12 -0
- package/lib/__templates__/nuxt-vue/AGENTS.md +42 -0
- package/lib/__templates__/nuxt-vue/README.md +73 -0
- package/lib/__templates__/nuxt-vue/_gitignore +24 -0
- package/lib/__templates__/nuxt-vue/_npmrc +23 -0
- package/lib/__templates__/nuxt-vue/app/app.vue +6 -0
- package/lib/__templates__/nuxt-vue/app/pages/index.vue +23 -0
- package/lib/__templates__/nuxt-vue/assets/css/main.css +24 -0
- package/lib/__templates__/nuxt-vue/nuxt.config.ts +116 -0
- package/lib/__templates__/nuxt-vue/package.json +35 -0
- package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +8759 -0
- package/lib/__templates__/nuxt-vue/postcss.config.mjs +8 -0
- package/lib/__templates__/nuxt-vue/public/favicon.ico +0 -0
- package/lib/__templates__/nuxt-vue/public/robots.txt +2 -0
- package/lib/__templates__/nuxt-vue/scripts/build.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +39 -0
- package/lib/__templates__/nuxt-vue/scripts/prepare.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/start.sh +21 -0
- package/lib/__templates__/nuxt-vue/server/api/hello.ts +10 -0
- package/lib/__templates__/nuxt-vue/server/middleware/logger.ts +10 -0
- package/lib/__templates__/nuxt-vue/server/routes/health.ts +10 -0
- package/lib/__templates__/nuxt-vue/tailwind.config.js +13 -0
- package/lib/__templates__/nuxt-vue/template.config.js +87 -0
- package/lib/__templates__/nuxt-vue/tsconfig.json +18 -0
- package/lib/__templates__/taro/.coze +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +19 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +2 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +151 -0
- package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -0
- package/lib/__templates__/taro/README.md +763 -0
- package/lib/__templates__/taro/_gitignore +40 -0
- package/lib/__templates__/taro/_npmrc +18 -0
- package/lib/__templates__/taro/babel.config.js +12 -0
- package/lib/__templates__/taro/config/dev.ts +9 -0
- package/lib/__templates__/taro/config/index.ts +238 -0
- package/lib/__templates__/taro/config/prod.ts +34 -0
- package/lib/__templates__/taro/eslint.config.mjs +135 -0
- package/lib/__templates__/taro/key/private.appid.key +0 -0
- package/lib/__templates__/taro/package.json +112 -0
- package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +23412 -0
- package/lib/__templates__/taro/pnpm-workspace.yaml +2 -0
- package/lib/__templates__/taro/project.config.json +15 -0
- package/lib/__templates__/taro/server/nest-cli.json +10 -0
- package/lib/__templates__/taro/server/package.json +40 -0
- package/lib/__templates__/taro/server/src/app.controller.ts +23 -0
- package/lib/__templates__/taro/server/src/app.module.ts +10 -0
- package/lib/__templates__/taro/server/src/app.service.ts +8 -0
- package/lib/__templates__/taro/server/src/interceptors/http-status.interceptor.ts +23 -0
- package/lib/__templates__/taro/server/src/main.ts +49 -0
- package/lib/__templates__/taro/server/tsconfig.json +24 -0
- package/lib/__templates__/taro/src/app.config.ts +11 -0
- package/lib/__templates__/taro/src/app.css +156 -0
- package/lib/__templates__/taro/src/app.tsx +9 -0
- package/lib/__templates__/taro/src/components/ui/accordion.tsx +159 -0
- package/lib/__templates__/taro/src/components/ui/alert-dialog.tsx +260 -0
- package/lib/__templates__/taro/src/components/ui/alert.tsx +60 -0
- package/lib/__templates__/taro/src/components/ui/aspect-ratio.tsx +36 -0
- package/lib/__templates__/taro/src/components/ui/avatar.tsx +84 -0
- package/lib/__templates__/taro/src/components/ui/badge.tsx +37 -0
- package/lib/__templates__/taro/src/components/ui/breadcrumb.tsx +117 -0
- package/lib/__templates__/taro/src/components/ui/button-group.tsx +83 -0
- package/lib/__templates__/taro/src/components/ui/button.tsx +67 -0
- package/lib/__templates__/taro/src/components/ui/calendar.tsx +394 -0
- package/lib/__templates__/taro/src/components/ui/card.tsx +108 -0
- package/lib/__templates__/taro/src/components/ui/carousel.tsx +228 -0
- package/lib/__templates__/taro/src/components/ui/checkbox.tsx +58 -0
- package/lib/__templates__/taro/src/components/ui/code-block.tsx +169 -0
- package/lib/__templates__/taro/src/components/ui/collapsible.tsx +71 -0
- package/lib/__templates__/taro/src/components/ui/command.tsx +385 -0
- package/lib/__templates__/taro/src/components/ui/context-menu.tsx +614 -0
- package/lib/__templates__/taro/src/components/ui/dialog.tsx +256 -0
- package/lib/__templates__/taro/src/components/ui/drawer.tsx +192 -0
- package/lib/__templates__/taro/src/components/ui/dropdown-menu.tsx +561 -0
- package/lib/__templates__/taro/src/components/ui/field.tsx +228 -0
- package/lib/__templates__/taro/src/components/ui/hover-card.tsx +282 -0
- package/lib/__templates__/taro/src/components/ui/input-group.tsx +197 -0
- package/lib/__templates__/taro/src/components/ui/input-otp.tsx +136 -0
- package/lib/__templates__/taro/src/components/ui/input.tsx +56 -0
- package/lib/__templates__/taro/src/components/ui/label.tsx +24 -0
- package/lib/__templates__/taro/src/components/ui/menubar.tsx +595 -0
- package/lib/__templates__/taro/src/components/ui/navigation-menu.tsx +264 -0
- package/lib/__templates__/taro/src/components/ui/pagination.tsx +118 -0
- package/lib/__templates__/taro/src/components/ui/popover.tsx +291 -0
- package/lib/__templates__/taro/src/components/ui/portal.tsx +19 -0
- package/lib/__templates__/taro/src/components/ui/progress.tsx +28 -0
- package/lib/__templates__/taro/src/components/ui/radio-group.tsx +64 -0
- package/lib/__templates__/taro/src/components/ui/resizable.tsx +346 -0
- package/lib/__templates__/taro/src/components/ui/scroll-area.tsx +34 -0
- package/lib/__templates__/taro/src/components/ui/select.tsx +438 -0
- package/lib/__templates__/taro/src/components/ui/separator.tsx +30 -0
- package/lib/__templates__/taro/src/components/ui/sheet.tsx +262 -0
- package/lib/__templates__/taro/src/components/ui/skeleton.tsx +17 -0
- package/lib/__templates__/taro/src/components/ui/slider.tsx +203 -0
- package/lib/__templates__/taro/src/components/ui/sonner.tsx +1 -0
- package/lib/__templates__/taro/src/components/ui/switch.tsx +55 -0
- package/lib/__templates__/taro/src/components/ui/table.tsx +142 -0
- package/lib/__templates__/taro/src/components/ui/tabs.tsx +114 -0
- package/lib/__templates__/taro/src/components/ui/textarea.tsx +54 -0
- package/lib/__templates__/taro/src/components/ui/toast.tsx +517 -0
- package/lib/__templates__/taro/src/components/ui/toggle-group.tsx +120 -0
- package/lib/__templates__/taro/src/components/ui/toggle.tsx +77 -0
- package/lib/__templates__/taro/src/components/ui/tooltip.tsx +455 -0
- package/lib/__templates__/taro/src/index.html +39 -0
- package/lib/__templates__/taro/src/lib/hooks/use-keyboard-offset.ts +37 -0
- package/lib/__templates__/taro/src/lib/measure.ts +115 -0
- package/lib/__templates__/taro/src/lib/platform.ts +12 -0
- package/lib/__templates__/taro/src/lib/utils.ts +6 -0
- package/lib/__templates__/taro/src/network.ts +39 -0
- package/lib/__templates__/taro/src/pages/index/index.config.ts +3 -0
- package/lib/__templates__/taro/src/pages/index/index.css +1 -0
- package/lib/__templates__/taro/src/pages/index/index.tsx +33 -0
- package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
- package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
- package/lib/__templates__/taro/src/presets/h5-navbar.tsx +238 -0
- package/lib/__templates__/taro/src/presets/h5-styles.ts +220 -0
- package/lib/__templates__/taro/src/presets/index.tsx +18 -0
- package/lib/__templates__/taro/stylelint.config.mjs +4 -0
- package/lib/__templates__/taro/template.config.js +68 -0
- package/lib/__templates__/taro/tsconfig.json +29 -0
- package/lib/__templates__/taro/types/global.d.ts +32 -0
- package/lib/__templates__/templates.json +52 -14
- package/lib/__templates__/vite/AGENTS.md +41 -0
- package/lib/__templates__/vite/README.md +190 -11
- package/lib/__templates__/vite/_gitignore +1 -0
- package/lib/__templates__/vite/eslint.config.mjs +6 -1
- package/lib/__templates__/vite/package.json +18 -2
- package/lib/__templates__/vite/pnpm-lock.yaml +1079 -2330
- package/lib/__templates__/vite/scripts/build.sh +4 -1
- package/lib/__templates__/vite/scripts/dev.sh +9 -2
- package/lib/__templates__/vite/scripts/start.sh +9 -3
- package/lib/__templates__/vite/server/routes/index.ts +31 -0
- package/lib/__templates__/vite/server/server.ts +65 -0
- package/lib/__templates__/vite/server/vite.ts +67 -0
- package/lib/__templates__/vite/src/main.ts +17 -48
- package/lib/__templates__/vite/template.config.js +47 -10
- package/lib/__templates__/vite/tsconfig.json +4 -3
- package/lib/__templates__/vite/vite.config.ts +5 -0
- package/lib/cli.js +909 -187
- package/package.json +7 -3
- package/lib/__templates__/expo/client/app/home.tsx +0 -1
- /package/lib/__templates__/expo/client/screens/{home → demo}/styles.ts +0 -0
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# <%= appName %>
|
|
2
2
|
|
|
3
|
-
这是一个基于
|
|
3
|
+
这是一个基于 Express + Vite + TypeScript + Tailwind CSS 的全栈 Web 应用项目,由扣子编程 CLI 创建。
|
|
4
|
+
|
|
5
|
+
**核心特性:**
|
|
6
|
+
- 🚀 前端:Vite + TypeScript + Tailwind CSS
|
|
7
|
+
- 🔧 后端:Express + TypeScript,提供 RESTful API
|
|
8
|
+
- 🔥 开发模式:Vite HMR + Express API,单进程启动
|
|
9
|
+
- 📦 生产模式:Express 静态服务 + API,高性能部署
|
|
4
10
|
|
|
5
11
|
## 快速开始
|
|
6
12
|
|
|
@@ -33,19 +39,149 @@ coze start
|
|
|
33
39
|
## 项目结构
|
|
34
40
|
|
|
35
41
|
```
|
|
36
|
-
├──
|
|
37
|
-
├──
|
|
38
|
-
│ ├──
|
|
39
|
-
│
|
|
40
|
-
│ └──
|
|
41
|
-
├──
|
|
42
|
-
├──
|
|
43
|
-
|
|
42
|
+
├── server/ # 后端服务器目录
|
|
43
|
+
│ ├── index.ts # express 服务器入口
|
|
44
|
+
│ ├── routes/ # API 路由目录
|
|
45
|
+
│ │ └── index.ts # 路由定义
|
|
46
|
+
│ └── vite.ts # Vite 集成逻辑
|
|
47
|
+
├── src/ # 前端源码目录
|
|
48
|
+
│ ├── index.ts # 前端应用入口(初始化)
|
|
49
|
+
│ ├── main.ts # 前端主逻辑文件
|
|
50
|
+
│ └── index.css # 全局样式(包含 Tailwind 指令)
|
|
51
|
+
├── index.html # HTML 入口文件
|
|
52
|
+
├── vite.config.ts # Vite 配置
|
|
53
|
+
├── tailwind.config.ts # Tailwind CSS 配置
|
|
54
|
+
└── tsconfig.json # TypeScript 配置
|
|
44
55
|
```
|
|
45
56
|
|
|
57
|
+
**目录说明:**
|
|
58
|
+
|
|
59
|
+
- **`server/`** - 后端服务器代码
|
|
60
|
+
- `server.ts` - 服务器主入口,负责创建和启动 Express 应用
|
|
61
|
+
- `routes/` - API 路由模块,支持按功能拆分路由
|
|
62
|
+
- `vite.ts` - Vite 开发服务器和静态文件服务集成
|
|
63
|
+
|
|
64
|
+
- **`src/`** - 前端应用代码
|
|
65
|
+
- 所有前端相关代码都在这里
|
|
66
|
+
|
|
67
|
+
**工作原理:**
|
|
68
|
+
|
|
69
|
+
- **开发模式** (`coze dev`):
|
|
70
|
+
- 运行 `server/server.ts` 启动 Express 服务器
|
|
71
|
+
- Vite 以 middleware 模式集成到 Express
|
|
72
|
+
- 前端支持 HMR(热模块替换)
|
|
73
|
+
- 后端 API 和前端在同一进程,端口 <%= port %>
|
|
74
|
+
|
|
75
|
+
- **生产模式** (`coze start`):
|
|
76
|
+
- `coze build` 构建前端 → `dist/` 目录
|
|
77
|
+
- `coze build` 构建后端 → `dist-server/index.js` (CommonJS 格式)
|
|
78
|
+
- 运行 `dist-server/index.js` 启动生产服务器
|
|
79
|
+
- Express 服务静态文件 + API 路由
|
|
80
|
+
- 单一 Node.js 进程,轻量高效
|
|
81
|
+
|
|
46
82
|
## 核心开发规范
|
|
47
83
|
|
|
48
|
-
### 1.
|
|
84
|
+
### 1. 后端 API 开发
|
|
85
|
+
|
|
86
|
+
**添加新的 API 路由**
|
|
87
|
+
|
|
88
|
+
在 `server/routes/index.ts` 中添加路由:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// GET 请求示例
|
|
92
|
+
router.get('/api/users', (req, res) => {
|
|
93
|
+
res.json({
|
|
94
|
+
users: [
|
|
95
|
+
{ id: 1, name: 'Alice' },
|
|
96
|
+
{ id: 2, name: 'Bob' },
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// POST 请求示例
|
|
102
|
+
router.post('/api/users', (req, res) => {
|
|
103
|
+
const userData = req.body;
|
|
104
|
+
// 处理业务逻辑
|
|
105
|
+
res.json({
|
|
106
|
+
success: true,
|
|
107
|
+
user: userData,
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// 动态路由参数
|
|
112
|
+
router.get('/api/users/:id', (req, res) => {
|
|
113
|
+
const userId = req.params.id;
|
|
114
|
+
res.json({
|
|
115
|
+
id: userId,
|
|
116
|
+
name: 'User ' + userId,
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**拆分路由模块**(推荐)
|
|
122
|
+
|
|
123
|
+
当路由变多时,可以按功能拆分:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
// server/routes/users.ts
|
|
127
|
+
import { Router } from 'express';
|
|
128
|
+
|
|
129
|
+
const router = Router();
|
|
130
|
+
|
|
131
|
+
router.get('/api/users', (req, res) => {
|
|
132
|
+
// 用户列表逻辑
|
|
133
|
+
res.json({ users: [] });
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
router.post('/api/users', (req, res) => {
|
|
137
|
+
// 创建用户逻辑
|
|
138
|
+
res.json({ success: true });
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
export default router;
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
然后在 `server/server.ts` 中注册:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import usersRouter from './routes/users';
|
|
148
|
+
|
|
149
|
+
// 注册路由
|
|
150
|
+
app.use(usersRouter);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**前端调用 API**
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
// GET 请求
|
|
157
|
+
async function getUsers() {
|
|
158
|
+
const response = await fetch('/api/users');
|
|
159
|
+
const data = await response.json();
|
|
160
|
+
console.log(data);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// POST 请求
|
|
164
|
+
async function createUser(name: string) {
|
|
165
|
+
const response = await fetch('/api/users', {
|
|
166
|
+
method: 'POST',
|
|
167
|
+
headers: {
|
|
168
|
+
'Content-Type': 'application/json',
|
|
169
|
+
},
|
|
170
|
+
body: JSON.stringify({ name }),
|
|
171
|
+
});
|
|
172
|
+
const data = await response.json();
|
|
173
|
+
console.log(data);
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**API 最佳实践**
|
|
178
|
+
|
|
179
|
+
- ✅ 所有 API 路由以 `/api` 开头,避免与前端路由冲突
|
|
180
|
+
- ✅ 使用 RESTful 设计:GET 查询、POST 创建、PUT 更新、DELETE 删除
|
|
181
|
+
- ✅ 返回统一的响应格式:`{ success: boolean, data?: any, error?: string }`
|
|
182
|
+
- ✅ 添加错误处理和参数验证
|
|
183
|
+
|
|
184
|
+
### 2. 样式开发
|
|
49
185
|
|
|
50
186
|
**使用 Tailwind CSS**
|
|
51
187
|
|
|
@@ -219,17 +355,31 @@ console.log(apiUrl); // https://api.example.com
|
|
|
219
355
|
|
|
220
356
|
## 技术栈
|
|
221
357
|
|
|
222
|
-
|
|
358
|
+
**前端:**
|
|
359
|
+
- **构建工具**: Vite 7.x
|
|
223
360
|
- **语言**: TypeScript 5.x
|
|
224
361
|
- **样式**: Tailwind CSS 3.x
|
|
362
|
+
|
|
363
|
+
**后端:**
|
|
364
|
+
- **框架**: Express 4.x
|
|
365
|
+
- **内置中间件**: express.json(), express.urlencoded(), express.static()
|
|
366
|
+
|
|
367
|
+
**工具:**
|
|
225
368
|
- **包管理器**: pnpm 9+
|
|
369
|
+
- **运行时**: Node.js 18+
|
|
370
|
+
- **开发工具**: tsx (TypeScript 执行器)
|
|
226
371
|
|
|
227
372
|
## 参考文档
|
|
228
373
|
|
|
374
|
+
**前端:**
|
|
229
375
|
- [Vite 官方文档](https://cn.vitejs.dev/)
|
|
230
376
|
- [TypeScript 官方文档](https://www.typescriptlang.org/zh/docs/)
|
|
231
377
|
- [Tailwind CSS 文档](https://tailwindcss.com/docs)
|
|
232
378
|
|
|
379
|
+
**后端:**
|
|
380
|
+
- [Express 官方文档](https://expressjs.com/)
|
|
381
|
+
- [Express 中文文档](https://expressjs.com/zh-cn/)
|
|
382
|
+
|
|
233
383
|
## 重要提示
|
|
234
384
|
|
|
235
385
|
1. **必须使用 pnpm** 作为包管理器
|
|
@@ -237,3 +387,32 @@ console.log(apiUrl); // https://api.example.com
|
|
|
237
387
|
3. **使用 Tailwind CSS** 进行样式开发,支持响应式和暗色模式
|
|
238
388
|
4. **环境变量必须以 `VITE_` 开头** 才能在客户端代码中访问
|
|
239
389
|
5. **开发时使用 `coze dev`**,支持热更新和快速刷新
|
|
390
|
+
6. **API 路由以 `/api` 开头**,避免与前端路由冲突
|
|
391
|
+
7. **单进程架构**:开发和生产环境都是前后端在同一进程中运行
|
|
392
|
+
|
|
393
|
+
## 常见问题
|
|
394
|
+
|
|
395
|
+
**Q: 如何分离前后端端口?**
|
|
396
|
+
|
|
397
|
+
如果需要前后端分离部署,可以:
|
|
398
|
+
- 前端:使用 `npx vite` 单独启动(默认端口 5173)
|
|
399
|
+
- 后端:修改 `server.ts`,移除 Vite middleware,单独启动
|
|
400
|
+
|
|
401
|
+
**Q: 如何添加数据库?**
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
# 安装数据库客户端(以 PostgreSQL 为例)
|
|
405
|
+
pnpm add pg
|
|
406
|
+
pnpm add -D @types/pg
|
|
407
|
+
|
|
408
|
+
# 在 server.ts 中使用
|
|
409
|
+
import { Pool } from 'pg';
|
|
410
|
+
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
**Q: 如何部署?**
|
|
414
|
+
|
|
415
|
+
1. 运行 `coze build` 构建前后端
|
|
416
|
+
2. 将整个项目上传到服务器
|
|
417
|
+
3. 运行 `pnpm install --prod`
|
|
418
|
+
4. 运行 `coze start` 启动服务
|
|
@@ -5,5 +5,10 @@ import { defineConfig, globalIgnores } from 'eslint/config';
|
|
|
5
5
|
export default defineConfig([
|
|
6
6
|
eslint.configs.recommended,
|
|
7
7
|
...tseslint.configs.recommended,
|
|
8
|
-
globalIgnores([
|
|
8
|
+
globalIgnores([
|
|
9
|
+
'dist/**',
|
|
10
|
+
'dist-server/**',
|
|
11
|
+
'node_modules/**',
|
|
12
|
+
'scripts/**',
|
|
13
|
+
]),
|
|
9
14
|
]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "<%= appName %>",
|
|
3
3
|
"version": "1.0.0",
|
|
4
|
-
"description": "Vanilla TypeScript application with Vite (HTML + CSS + TS)",
|
|
4
|
+
"description": "Vanilla TypeScript application with Express + Vite (HTML + CSS + TS + Node API)",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "bash ./scripts/build.sh",
|
|
7
7
|
"dev": "bash ./scripts/dev.sh",
|
|
@@ -10,13 +10,23 @@
|
|
|
10
10
|
"start": "bash ./scripts/start.sh",
|
|
11
11
|
"ts-check": "tsc -p tsconfig.json"
|
|
12
12
|
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@supabase/supabase-js": "2.95.3",
|
|
15
|
+
"dotenv": "^17.2.3",
|
|
16
|
+
"express": "^4.21.2"
|
|
17
|
+
},
|
|
13
18
|
"devDependencies": {
|
|
19
|
+
"@types/express": "^5.0.0",
|
|
20
|
+
"@types/node": "^22.10.5",
|
|
14
21
|
"autoprefixer": "^10.4.20",
|
|
15
|
-
"coze-coding-dev-sdk": "^0.7.
|
|
22
|
+
"coze-coding-dev-sdk": "^0.7.16",
|
|
23
|
+
"esbuild": "^0.24.2",
|
|
16
24
|
"eslint": "^9",
|
|
17
25
|
"only-allow": "^1.2.2",
|
|
18
26
|
"postcss": "^8.4.49",
|
|
19
27
|
"tailwindcss": "^3.4.17",
|
|
28
|
+
"tsup": "^8.3.5",
|
|
29
|
+
"tsx": "^4.19.2",
|
|
20
30
|
"typescript": "^5.6.0",
|
|
21
31
|
"typescript-eslint": "^8",
|
|
22
32
|
"vite": "^7.2.4"
|
|
@@ -24,5 +34,11 @@
|
|
|
24
34
|
"packageManager": "pnpm@9.0.0",
|
|
25
35
|
"engines": {
|
|
26
36
|
"pnpm": ">=9.0.0"
|
|
37
|
+
},
|
|
38
|
+
"pnpm": {
|
|
39
|
+
"overrides": {
|
|
40
|
+
"esbuild": "^0.27.2",
|
|
41
|
+
"is-generator-function": "1.0.10"
|
|
42
|
+
}
|
|
27
43
|
}
|
|
28
44
|
}
|