tauri-create

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Tauri 项目创建

Tauri Project Creation

功能概述

Feature Overview

交互式创建 Tauri 跨平台桌面应用项目。引导用户完成模板选择、UI 框架安装、Git 初始化、端口配置等步骤。
Interactively create cross-platform desktop application projects with Tauri. Guide users through steps such as template selection, UI framework installation, Git initialization, and port configuration.

交互方式

Interaction Method

所有询问尽量使用
AskUserQuestion
工具进行交互式问答
All inquiries should use the
AskUserQuestion
tool for interactive Q&A as much as possible.

快速创建流程

Quick Creation Process

步骤 1:获取项目信息

Step 1: Get Project Information

检查当前目录:执行
ls -A
检查当前目录是否为空。
决定创建位置
  • 当前目录为空:使用
    AskUserQuestion
    询问用户是在当前目录创建还是创建子目录
  • 当前目录非空:告知用户将创建子目录
选择模板:使用
AskUserQuestion
询问用户模板选择,默认推荐
vue-ts
模板参数技术栈
vue-ts
Vue + TypeScript(推荐)
vue
Vue
react-ts
React + TypeScript
react
React
svelte-ts
Svelte + TypeScript
svelte
Svelte
vanilla-ts
Vanilla + TypeScript
vanilla
Vanilla JS
执行创建
在当前目录创建(空目录):
bash
pnpm create tauri-app . --template <模板> --yes
pnpm install
创建子目录:
bash
pnpm create tauri-app <项目名> --template <模板> --yes
cd <项目名>
pnpm install
Check Current Directory: Execute
ls -A
to check if the current directory is empty.
Determine Creation Location:
  • If the current directory is empty: Use
    AskUserQuestion
    to ask the user whether to create in the current directory or create a subdirectory
  • If the current directory is not empty: Inform the user that a subdirectory will be created
Select Template: Use
AskUserQuestion
to ask the user for template selection, with
vue-ts
as the default recommendation.
Template ParameterTech Stack
vue-ts
Vue + TypeScript (Recommended)
vue
Vue
react-ts
React + TypeScript
react
React
svelte-ts
Svelte + TypeScript
svelte
Svelte
vanilla-ts
Vanilla + TypeScript
vanilla
Vanilla JS
Execute Creation:
Create in current directory (empty directory):
bash
pnpm create tauri-app . --template <模板> --yes
pnpm install
Create subdirectory:
bash
pnpm create tauri-app <项目名> --template <模板> --yes
cd <项目名>
pnpm install

步骤 2:Git 初始化(建议)

Step 2: Git Initialization (Recommended)

检查 Git 状态:执行
git rev-parse --git-dir > /dev/null 2>&1
检查当前目录是否已是 git 仓库。
  • 如已是 git 仓库:告知用户,跳过初始化,后续步骤会直接提交
  • 如非 git 仓库:使用
    AskUserQuestion
    询问用户是否需要 Git 版本管理
告知后续每步操作都会提交一次 git,记录创建过程。
如需要初始化,立即执行:
bash
git init && git add . && git commit -m "init"
Check Git Status: Execute
git rev-parse --git-dir > /dev/null 2>&1
to check if the current directory is already a git repository.
  • If it is already a git repository: Inform the user, skip initialization, and subsequent steps will commit directly
  • If it is not a git repository: Use
    AskUserQuestion
    to ask the user if they need Git version control
Inform the user that each subsequent step will be committed to git to record the creation process.
If initialization is needed, execute immediately:
bash
git init && git add . && git commit -m "init"

步骤 3:安装 UI 框架

Step 3: Install UI Framework

使用
AskUserQuestion
询问用户:是否需要使用 UI 框架?
如需要,根据已选择的模板推荐合适的框架,并立即执行安装命令。
如已选择 Git,安装完成后提交:
bash
git add .
git commit -m "feat: add UI framework"
Use
AskUserQuestion
to ask the user: Do you need to use a UI framework?
If yes, recommend a suitable framework based on the selected template and execute the installation command immediately.
If Git is selected, commit after installation is complete:
bash
git add .
git commit -m "feat: add UI framework"

步骤 4:端口配置

Step 4: Port Configuration

使用
AskUserQuestion
询问用户:是否使用默认的 1420 端口?
如不是,让用户指定新端口号,立即编辑
vite.config.ts
tauri.conf.json
修改端口。
如已选择 Git,修改完成后提交:
bash
git add .
git commit -m "config: change port to <新端口>"
Use
AskUserQuestion
to ask the user: Do you want to use the default port 1420?
If not, ask the user to specify a new port number and immediately edit
vite.config.ts
and
tauri.conf.json
to change the port.
If Git is selected, commit after modification is complete:
bash
git add .
git commit -m "config: change port to <新端口>"

步骤 5:安装 window-state 插件

Step 5: Install window-state Plugin

使用
AskUserQuestion
询问用户:是否需要窗口状态记忆功能(桌面端)?
说明好处:自动记住窗口位置和大小,下次打开保持原样。
如需要,立即执行:
bash
pnpm tauri add window-state
如已选择 Git,安装完成后提交:
bash
git add .
git commit -m "feat: add window-state plugin"
Use
AskUserQuestion
to ask the user: Do you need window state memory functionality (desktop)?
Explain the benefits: Automatically remembers window position and size, and retains them when opened next time.
If yes, execute immediately:
bash
pnpm tauri add window-state
If Git is selected, commit after installation is complete:
bash
git add .
git commit -m "feat: add window-state plugin"

步骤 6:创建 AGENTS.md

Step 6: Create AGENTS.md

提示 AI 根据项目当前情况生成一份 AGENTS.md 文件,内容需要额外包含:提醒使用
tauri-best-practices
技能。
如已选择 Git,创建完成后提交:
bash
git add AGENTS.md
git commit -m "docs: add AGENTS.md"
Prompt the AI to generate an AGENTS.md file based on the current project situation, with additional content including: a reminder to use the
tauri-best-practices
skill.
If Git is selected, commit after creation is complete:
bash
git add AGENTS.md
git commit -m "docs: add AGENTS.md"

步骤 7:告知开发命令

Step 7: Inform Development Commands

创建完成后告知用户:
bash
pnpm dev          # 纯网页开发
pnpm tauri dev    # 开发模式
pnpm tauri build  # 构建应用
After creation is complete, inform the user of:
bash
pnpm dev          # Pure web development
pnpm tauri dev    # Development mode
pnpm tauri build  # Build application

使用示例

Usage Examples

场景 1:全新项目创建(空目录)

Scenario 1: Create a New Project (Empty Directory)

用户输入:"帮我创建一个 Tauri 应用"
交互流程
  1. 检查当前目录为空
  2. 询问用户:在当前目录创建还是创建子目录?
  3. 询问模板选择(推荐 vue-ts)
  4. 执行创建命令
  5. 询问是否初始化 Git
  6. 询问是否需要 UI 框架(根据模板推荐)
  7. 询问端口配置
  8. 询问是否安装 window-state 插件
  9. 创建 AGENTS.md
  10. 告知开发命令
User Input: "Help me create a Tauri application"
Interaction Flow:
  1. Check that the current directory is empty
  2. Ask the user: Create in the current directory or create a subdirectory?
  3. Ask for template selection (recommend vue-ts)
  4. Execute creation command
  5. Ask whether to initialize Git
  6. Ask whether a UI framework is needed (recommended based on template)
  7. Ask about port configuration
  8. Ask whether to install the window-state plugin
  9. Create AGENTS.md
  10. Inform development commands

场景 2:指定模板创建

Scenario 2: Create with Specified Template

用户输入:"用 React 创建一个 Tauri 项目"
处理方式
  1. 直接使用 react-ts 模板(推荐 TypeScript)
  2. 如用户明确说不使用 TS,则使用 react 模板
  3. 其余流程同场景 1
User Input: "Create a Tauri project with React"
Handling Method:
  1. Directly use the react-ts template (TypeScript recommended)
  2. If the user explicitly says not to use TS, use the react template
  3. The rest of the process is the same as Scenario 1

场景 3:快速创建(跳过交互)

Scenario 3: Quick Creation (Skip Interaction)

用户输入:"快速创建一个基础的 Tauri 项目,不需要额外配置"
处理方式
  1. 使用默认模板(vue-ts)
  2. 创建子目录或使用当前目录(如为空)
  3. 跳过 Git、UI 框架、端口、插件等询问
  4. 仅完成基础创建和依赖安装
User Input: "Quickly create a basic Tauri project without additional configuration"
Handling Method:
  1. Use the default template (vue-ts)
  2. Create a subdirectory or use the current directory (if empty)
  3. Skip inquiries about Git, UI frameworks, ports, plugins, etc.
  4. Only complete basic creation and dependency installation

场景 4:在现有项目中创建

Scenario 4: Create in an Existing Project

用户输入:"在当前目录创建 Tauri 项目"(当前目录非空)
处理方式
  1. 告知用户将创建子目录
  2. 询问项目名称
  3. 在子目录中完成创建
User Input: "Create a Tauri project in the current directory" (current directory is not empty)
Handling Method:
  1. Inform the user that a subdirectory will be created
  2. Ask for the project name
  3. Complete creation in the subdirectory

注意事项

Notes

  • 环境要求:确保已安装 Node.js 18+ 和 pnpm
  • Rust 工具链:如需编写自定义 Rust 代码,需额外安装 Rust
  • 此技能范围:仅负责项目创建和初始配置,不涉及后续开发
  • 插件安装限制
    pnpm tauri add
    一次只能添加一个插件,需多次执行
  • Git 提交策略:每完成一个配置步骤立即提交,记录创建过程
  • 端口冲突:如 1420 端口被占用,建议用户修改端口
  • 最佳实践:创建完成后提醒用户参考
    tauri-best-practices
    技能
  • Environment Requirements: Ensure Node.js 18+ and pnpm are installed
  • Rust Toolchain: If you need to write custom Rust code, you need to install Rust additionally
  • Skill Scope: Only responsible for project creation and initial configuration, not subsequent development
  • Plugin Installation Limit:
    pnpm tauri add
    can only add one plugin at a time, so it needs to be executed multiple times
  • Git Commit Strategy: Commit immediately after each configuration step to record the creation process
  • Port Conflict: If port 1420 is occupied, it is recommended that the user change the port
  • Best Practices: Remind users to refer to the
    tauri-best-practices
    skill after creation is complete

参考资源

Reference Resources