Web artifacts builder

From findscripter/everything-skills · View interactive version

Web artifacts builder is an AI agent skill from the GitHub repository findscripter/everything-skills. 当需要为 claude.ai 构建含状态管理/路由/shadcn 组件的复杂多组件 HTML 制品(artifact)时使用;用脚手架初始化 React+TS+Vite 工程并打包为单文件 bundle.html 产物;不适用于简单的单文件 HTML/JSX 制品;触发词:web artifact、artifacts、复杂制品、shadcn、单文件HTML、bundle.html、React制品

How to use this skill

Skill file

何时使用

用于为 claude.ai 构建复杂、多组件的 HTML 制品(artifact),尤其当制品需要:状态管理、客户端路由,或大量 shadcn/ui 组件时。技术栈固定为 React 18 + TypeScript + Vite + Tailwind CSS 3.4.1 + shadcn/ui,最终用 Parcel 打包并内联成单个自包含的 bundle.html,可直接作为 artifact 分享给用户。

不该用的边界:

环境要求:Node.js ≥ 18(脚本会自动检测;Node 18 会把 Vite 固定到 5.4.11,Node 20+ 用 latest);需要 bash 执行脚本,未装 pnpm 时脚本会自动 npm install -g pnpm。脚本目录需包含 shadcn-components.tar.gz(预置 40+ 组件)。

步骤

  1. 初始化工程——运行脚手架,生成已配好的 React 工程。
  2. 开发制品——编辑生成的源码(src/),用 @/ 路径别名导入 shadcn 组件。
  3. 打包为单文件——运行打包脚本,产出 bundle.html。
  4. 分享产物——把 bundle.html 作为 artifact 发给用户查看。
  5. (可选)测试/可视化——仅在必要或用户要求时进行。

重要:通常不要前置测试,这会拖慢「请求 → 看到成品」的链路。先呈现制品,待用户要求或出现问题时再测。

指令:

# 步骤 1:初始化(在 skill 的 scripts/ 上下文中执行)
bash scripts/init-artifact.sh <project-name>
cd <project-name>

# 该脚本完成:React+TS(Vite)、Tailwind 3.4.1 + shadcn 主题、
#   @/ 路径别名、预置 40+ shadcn 组件、Radix UI 全量依赖、
#   .parcelrc 打包配置、Node 18+ 兼容(自动锁定 Vite 版本)

# 步骤 2:本地开发预览
pnpm dev

# 步骤 3:打包为单文件 artifact(在项目根目录执行)
bash scripts/bundle-artifact.sh
# 产出 bundle.html —— 所有 JS/CSS/依赖均已内联

bundle-artifact.sh 内部:安装 parcel @parcel/config-default parcel-resolver-tspaths html-inline → 生成带路径别名解析的 .parcelrc → parcel build index.html --no-source-maps → 用 html-inline 把 dist/index.html 内联为 bundle.html。前提:项目根目录必须有 index.html 入口。

设计与风格指令(务必遵守)

为避免所谓「AI slop」(廉价 AI 既视感),避免:过度居中布局、紫色渐变、千篇一律的统一圆角、Inter 字体。追求有层次、有差异化的版式。

示例

// 用 @/ 别名导入预置 shadcn 组件
import { Button } from '@/components/ui/button'
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'
import { Dialog, DialogContent, DialogTrigger } from '@/components/ui/dialog'

export default function App() {
  return (
    <Card>
      <CardHeader><CardTitle>仪表盘</CardTitle></CardHeader>
      <CardContent>
        <Dialog>
          <DialogTrigger asChild><Button>打开</Button></DialogTrigger>
          <DialogContent>内容</DialogContent>
        </Dialog>
      </CardContent>
    </Card>
  )
}

预置组件(40+)涵盖:accordion、alert、avatar、badge、button、calendar、card、carousel、checkbox、command、context-menu、dialog、drawer、dropdown-menu、form、hover-card、input、label、menubar、navigation-menu、popover、progress、radio-group、resizable、scroll-area、select、separator、sheet、skeleton、slider、sonner、switch、table、tabs、textarea、toast、toggle、toggle-group、tooltip 等。

注意事项

互见

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.