Tauri
เว็บวิวบนบิลด์ Vite การตั้งค่าของ Vite และตัวสลับธีมที่ไม่ต้องใช้เฟรมเวิร์ก
แอป Tauri คือแอป Vite ในหน้าต่างเนทีฟ ดังนั้นการตั้งค่าเว็บคือการตั้งค่าทั้งหมด นามแฝง ลำดับส่วนขยาย และรูทคือสิ่งที่อยู่ในหน้า Vite
สร้างโปรเจกต์
pnpm create tauri-app@latest my-app --template react-ts
cd my-app
pnpm add @hanzo/ui @hanzo/gui react-native-webตั้งค่า Vite
vite.config.ts
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [react()],
clearScreen: false,
server: { port: 1420, strictPort: true },
resolve: {
alias: {
'react-native': 'react-native-web',
'@react-native/assets-registry/registry': 'react-native-web/dist/modules/AssetRegistry',
},
extensions: ['.web.js', '.web.jsx', '.web.ts', '.web.tsx', '.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'],
},
})server.port และ clearScreen เป็นธรรมเนียมของ Tauri เองสำหรับหน้าต่างพัฒนา บล็อก resolve เป็นของไลบรารี
ติดตั้งรูท
src/main.tsx
import { createRoot } from 'react-dom/client'
import { Hanzo } from '@hanzo/ui'
import { App } from './App'
createRoot(document.getElementById('root')!).render(
<Hanzo>
<App />
</Hanzo>,
)ตัวสลับธีมโดยไม่ใช้เฟรมเวิร์ก
ThemeToggle จาก @hanzo/ui/product ทำงานโดยไม่ต้องพึ่งเฟรมเวิร์ก เมื่อถูกควบคุม มันวาดปุ่มและรายงานธีมถัดไป แอปเก็บค่าแล้วส่งให้รูท
import { useState } from 'react'
import { Hanzo } from '@hanzo/ui'
import { ThemeToggle, type ThemeMode } from '@hanzo/ui/product'
export function App() {
const [theme, setTheme] = useState<ThemeMode>('dark')
return (
<Hanzo theme={theme}>
<ThemeToggle theme={theme} onToggle={setTheme} />
</Hanzo>
)
}การผูก Next ของตัวสลับเดียวกันอยู่ที่ซับพาธของตัวเอง @hanzo/ui/product/theme-toggle-next เพื่อให้โฮสต์ Tauri, Vite หรือ Express ไม่ดึง Next เข้ากราฟเพียงเพราะนำเข้าชั้นผลิตภัณฑ์