浏览文档

来源已核对8a1541c4a3ff

Web Artifacts Builder - Claude 的 React Artifact 技能

Web Artifacts Builder 技能如何把 React 和 Tailwind 打包成带 shadcn 组件的单文件 HTML artifact——完整流程解读。

Anthropic · Web Artifacts Builder

保留既有编辑内容,当前固定版本的官方参考另标为英文;旧译文不代表最新源文件的全文翻译。

这里保留既有编辑译文;如有最新完整官方参考,会在下方独立提供英文原文。

源码在这里作为文档呈现。本站尚未执行或测试这些工作流程。

本页目录

概览

官方描述:"Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using React, Tailwind CSS, shadcn/ui. For complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file artifacts."

注意适用边界:简单的单文件 artifact 不需要这个技能。它服务于项目复杂到装不进一个 JSX 块的时刻。

这个技能如何工作

SKILL.md 是一条五步流水线,外加设计指引:

  1. 初始化:用 scripts/init-artifact.sh 生成预配置的 React + Tailwind + shadcn/ui 工作区
  2. 开发:真组件、状态管理、路由都可用
  3. 打包:用 scripts/bundle-artifact.sh 把一切压成单个 HTML 文件
  4. 交付 artifact 给用户
  5. 测试/预览(可选的验证步骤)

技能里自带 shadcn-components.tar.gz 组件包,无需联网也能安装组件。

技能文件夹里有什么

  • scripts/init-artifact.sh - 项目脚手架
  • scripts/bundle-artifact.sh - 单文件 HTML 打包器
  • scripts/shadcn-components.tar.gz - 离线组件库
  • SKILL.md、LICENSE.txt

对你自己写技能的启示

  • 可执行脚本胜过操作说明:与其用文字描述环境搭建,不如像它一样直接给 Claude 可运行的 shell 脚本。
  • 打包离线依赖(那个 shadcn 压缩包)让技能能在沙箱环境工作——大多数社区技能都漏了这个细节。

在 GitHub 查看

skills/web-artifacts-builder

当前官方参考 · 英文8a1541c4a3ff

以下英文原文对应上方固定版本,只作为文档展示。相关脚本与资源仍由上游仓库提供,单篇文字不等于完整安装包。

Web Artifacts Builder

To build powerful frontend claude.ai artifacts, follow these steps:

  1. Initialize the frontend repo using scripts/init-artifact.sh
  2. Develop your artifact by editing the generated code
  3. Bundle all code into a single HTML file using scripts/bundle-artifact.sh
  4. Display artifact to user
  5. (Optional) Test the artifact

Stack: React 18 + TypeScript + Vite + Parcel (bundling) + Tailwind CSS + shadcn/ui

Design & Style Guidelines

VERY IMPORTANT: To avoid what is often referred to as "AI slop", avoid using excessive centered layouts, purple gradients, uniform rounded corners, and Inter font.

Quick Start

Step 1: Initialize Project

Run the initialization script to create a new React project:

bash scripts/init-artifact.sh <project-name>
cd <project-name>

This creates a fully configured project with:

  • ✅ React + TypeScript (via Vite)
  • ✅ Tailwind CSS 3.4.1 with shadcn/ui theming system
  • ✅ Path aliases (@/) configured
  • ✅ 40+ shadcn/ui components pre-installed
  • ✅ All Radix UI dependencies included
  • ✅ Parcel configured for bundling (via .parcelrc)
  • ✅ Node 18+ compatibility (auto-detects and pins Vite version)

Step 2: Develop Your Artifact

To build the artifact, edit the generated files. See Common Development Tasks below for guidance.

Step 3: Bundle to Single HTML File

To bundle the React app into a single HTML artifact:

bash scripts/bundle-artifact.sh

This creates bundle.html - a self-contained artifact with all JavaScript, CSS, and dependencies inlined. This file can be directly shared in Claude conversations as an artifact.

Requirements: Your project must have an index.html in the root directory.

What the script does:

  • Installs bundling dependencies (parcel, @parcel/config-default, parcel-resolver-tspaths, html-inline)
  • Creates .parcelrc config with path alias support
  • Builds with Parcel (no source maps)
  • Inlines all assets into single HTML using html-inline

Step 4: Share Artifact with User

Finally, share the bundled HTML file in conversation with the user so they can view it as an artifact.

Step 5: Testing/Visualizing the Artifact (Optional)

Note: This is a completely optional step. Only perform if necessary or requested.

To test/visualize the artifact, use available tools (including other Skills or built-in tools like Playwright or Puppeteer). In general, avoid testing the artifact upfront as it adds latency between the request and when the finished artifact can be seen. Test later, after presenting the artifact, if requested or if issues arise.

Reference