cloudwerk-config
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloudwerk Configuration
Cloudwerk 配置参考
Reference for — the main configuration file for Cloudwerk applications.
cloudwerk.config.tscloudwerk.config.tsWhen to Apply
适用场景
Reference these guidelines when:
- Creating a new Cloudwerk project
- Choosing between hono-jsx and react renderers
- Configuring Vite plugins (Tailwind CSS, etc.)
- Setting up path aliases
- Troubleshooting build or rendering issues
参考本文档的场景包括:
- 创建新的 Cloudwerk 项目
- 在 hono-jsx 和 react 渲染器之间做选择
- 配置 Vite 插件(如 Tailwind CSS 等)
- 设置路径别名
- 排查构建或渲染问题
Configuration File
配置文件
Every Cloudwerk app has a at the project root:
cloudwerk.config.tstypescript
import { defineConfig } from '@cloudwerk/core'
export default defineConfig({
// Configuration options here
})每个 Cloudwerk 应用的项目根目录下都有一个 文件:
cloudwerk.config.tstypescript
import { defineConfig } from '@cloudwerk/core'
export default defineConfig({
// Configuration options here
})Renderer Selection
渲染器选择
hono-jsx (Default)
hono-jsx(默认)
Lightweight server-side rendering using Hono's built-in JSX. No client-side hydration or React hooks.
typescript
import { defineConfig } from '@cloudwerk/core'
import tailwindcss from '@tailwindcss/vite'
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'path'
const __dirname = dirname(fileURLToPath(import.meta.url))
export default defineConfig({
ui: {
renderer: 'hono-jsx',
},
vite: {
plugins: [tailwindcss()],
resolve: {
alias: {
'@': resolve(__dirname, './'),
},
},
},
})Use hono-jsx when:
- Building server-rendered pages without client interactivity
- Minimizing bundle size
- Building API-heavy applications with minimal UI
JSX differences with hono-jsx:
- Use instead of
classclassName - Use instead of
forhtmlFor - No React hooks (,
useState, etc.)useEffect - No directive support
'use client'
使用 Hono 内置的 JSX 实现轻量级服务端渲染。无需客户端水合或 React 钩子。
typescript
import { defineConfig } from '@cloudwerk/core'
import tailwindcss from '@tailwindcss/vite'
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'path'
const __dirname = dirname(fileURLToPath(import.meta.url))
export default defineConfig({
ui: {
renderer: 'hono-jsx',
},
vite: {
plugins: [tailwindcss()],
resolve: {
alias: {
'@': resolve(__dirname, './'),
},
},
},
})推荐使用 hono-jsx 的场景:
- 构建无客户端交互的服务端渲染页面
- 最小化打包体积
- 构建以 API 为主、UI 极简的应用
hono-jsx 的 JSX 语法差异:
- 使用 而非
classclassName - 使用 而非
forhtmlFor - 不支持 React 钩子(、
useState等)useEffect - 不支持 指令
'use client'
react
react
Full React SSR with hydration support. Enables client components, React hooks, and interactive UIs.
typescript
import { defineConfig } from '@cloudwerk/core'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
ui: {
renderer: 'react',
},
vite: {
plugins: [tailwindcss()],
},
})Use react when:
- Building interactive UIs with client-side state
- Using React hooks (,
useState,useEffect)useRef - Need components
'use client' - Using React component libraries
JSX conventions with react:
- Use instead of
classNameclass - Use instead of
htmlForfor - Full React hooks support
- directive for client components
'use client'
完整的 React 服务端渲染,支持水合。可启用客户端组件、React 钩子和交互式 UI。
typescript
import { defineConfig } from '@cloudwerk/core'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
ui: {
renderer: 'react',
},
vite: {
plugins: [tailwindcss()],
},
})推荐使用 react 的场景:
- 构建带有客户端状态的交互式 UI
- 使用 React 钩子(、
useState、useEffect)useRef - 需要 组件
'use client' - 使用 React 组件库
react 的 JSX 语法规范:
- 使用 而非
classNameclass - 使用 而非
htmlForfor - 完全支持 React 钩子
- 为客户端组件使用 指令
'use client'
Vite Configuration
Vite 配置
The key accepts any Vite configuration:
vitetypescript
export default defineConfig({
vite: {
// Vite plugins
plugins: [tailwindcss()],
// Path aliases
resolve: {
alias: {
'@': resolve(__dirname, './'),
'@components': resolve(__dirname, './app/components'),
},
},
// Build options
build: {
sourcemap: true,
},
},
})vitetypescript
export default defineConfig({
vite: {
// Vite plugins
plugins: [tailwindcss()],
// Path aliases
resolve: {
alias: {
'@': resolve(__dirname, './'),
'@components': resolve(__dirname, './app/components'),
},
},
// Build options
build: {
sourcemap: true,
},
},
})Quick Comparison
快速对比
| Feature | hono-jsx | react |
|---|---|---|
| CSS classes | | |
| Client components | No | Yes ( |
| React hooks | No | Yes |
| Bundle size | Smaller | Larger |
| Hydration | No | Yes |
| Best for | Content sites, APIs | Interactive apps |
| 特性 | hono-jsx | react |
|---|---|---|
| CSS 类名 | | |
| 客户端组件 | 不支持 | 支持(通过 |
| React 钩子 | 不支持 | 支持 |
| 打包体积 | 更小 | 更大 |
| 水合机制 | 无 | 有 |
| 最佳适用场景 | 内容站点、API 服务 | 交互式应用 |