vscode-webview-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVS Code Webview UI
VS Code Webview UI
Overview
概述
This skill assists in developing the React application that powers VS Code webview surfaces. It covers the workspace, which is bundled with Vite and communicates with the extension host via the helper.
webview-uibridge/vscode本技能可协助开发为VS Code Webview界面提供支持的React应用。它涵盖了工作区,该工作区通过Vite进行打包,并通过工具与扩展宿主进行通信。
webview-uibridge/vscodeProject Structure
项目结构
The package follows this structure:
webview-uiwebview-ui/
├── src/
│ ├── components/ # Shared visual components reused across features
│ │ └── ui/ # shadcn/ui component library
│ ├── hooks/ # Shared React hooks
│ ├── features/
│ │ └── {feature}/
│ │ ├── index.tsx # Feature entry component rendered from routing
│ │ ├── components/# Feature-specific components
│ │ └── hooks/ # Feature-specific hooks
│ ├── bridge/ # Messaging helpers for VS Code <-> webview
│ └── index.tsx # Runtime router that mounts the selected feature
├── public/ # Static assets copied verbatim by Vite
├── vite.config.ts # Vite build configuration
└── README.mdwebview-uiwebview-ui/
├── src/
│ ├── components/ # 跨功能复用的共享视觉组件
│ │ └── ui/ # shadcn/ui组件库
│ ├── hooks/ # 共享React hooks
│ ├── features/
│ │ └── {feature}/
│ │ ├── index.tsx # 由路由挂载的功能入口组件
│ │ ├── components/# 功能专属组件
│ │ └── hooks/ # 功能专属hooks
│ ├── bridge/ # VS Code <-> Webview的消息通信工具
│ └── index.tsx # 用于挂载选定功能的运行时路由
├── public/ # Vite直接复制的静态资源
├── vite.config.ts # Vite构建配置
└── README.mdCoding Guidelines
编码规范
- Shared Modules: Prefer shared modules under and
src/componentsbefore introducing feature-local code.src/hooks - Feature Boundaries: Add feature-only utilities inside the nested or
components/directories to keep boundaries clear.hooks/ - Styling: Keep styling in Tailwind-style utility classes (see for base tokens) and avoid inline styles when reusable classes exist.
src/app.css - Messaging: Exchange messages with the extension via and subscribe through
vscode.postMessageinside React effects.window.addEventListener('message', …) - Configuration: When adding new steering or config references, obtain paths through the shared utilities from the extension layer.
ConfigManager
- 共享模块:在添加功能本地代码之前,优先使用和
src/components下的共享模块。src/hooks - 功能边界:将功能专属工具放在嵌套的或
components/目录中,以明确边界。hooks/ - 样式:采用Tailwind风格的工具类进行样式编写(基础令牌可查看),当存在可复用类时避免使用内联样式。
src/app.css - 消息通信:通过与扩展交换消息,并在React effects中通过
vscode.postMessage进行订阅。window.addEventListener('message', …) - 配置:添加新的控制或配置引用时,通过扩展层的共享工具获取路径。
ConfigManager
Testing & Quality
测试与质量
- Integration Tests: Use Playwright or Cypress style integration tests if adding complex interactions (tests live under the repo-level ).
tests/ - Pre-commit Checks: Run and
npm run lintbefore committing to ensure TypeScript and bundler checks pass.npm run build
- 集成测试:如果添加复杂交互,可使用Playwright或Cypress风格的集成测试(测试文件位于仓库级别的目录下)。
tests/ - 提交前检查:提交前运行和
npm run lint,确保TypeScript和打包检查通过。npm run build