convert-tanstack-app-to-web-component

Refactors a standalone TanStack-based application (React/Vue/Solid) into a standard Web Component (Custom Element), enabling framework-agnostic injection into legacy apps or micro-frontends.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "convert-tanstack-app-to-web-component" with this command: npx skills add visio-ai/teste-skills/visio-ai-teste-skills-convert-tanstack-app-to-web-component

Step 1 — Install the required dependency

npm install @r2wc/react-to-web-component

Step 2 — Create src/App.tsx (body-level app component)

Extract the body content from src/routes/__root.tsx into a standalone React component. This component must NOT render <html>, <head>, or <body> — only the visual content (Header + router outlet). The original __root.tsx stays untouched for the SSR build.


Step 3 — Create src/widget.tsx (custom element entry)

  • Import App from src/App.tsx
  • Use @r2wc/react-to-web-component to wrap it as a custom element
  • Inject Tailwind CSS into the Shadow DOM using Vite's ?inline import:
import styles from './styles.css?inline'
// pass styles to r2wc options so they are adopted into the shadow root
  • Register the custom element, for %app-name get the name from the package.json name:
customElements.define('%app-name', TanstackAppElement)

Step 4 — Switch to Memory Router for the WC build

Browser history routing conflicts with the host page URL. In src/widget.tsx, create the router using createMemoryHistory:

import { createMemoryHistory } from '@tanstack/react-router'

const router = createRouter({
  routeTree,
  history: createMemoryHistory({ initialEntries: ['/'] }),
})

Update src/router.tsx to accept an optional history parameter so the same factory works for both SSR and WC builds.


Step 5 — Create vite.config.wc.ts (standalone lib build)

The WC build must NOT use TanStack Start's SSR plugins (tanstackStart(), nitro(), devtools()). Create a separate Vite config in lib mode:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
  plugins: [react(), tailwindcss(), tsconfigPaths()],
  define: {
    'process.env.NODE_ENV': JSON.stringify('production'),
  },
  build: {
    outDir: 'webcomponent',
    lib: {
      entry: 'src/widget.tsx',
      name: 'TanstackAppWC',
      fileName: '%app-name',
      formats: ['iife'], // single self-executing bundle for easy <script> embedding
    },
  },
})

Add the webcomponent dir to .gitignore


Step 6 — Add build:wc script to package.json

"build:wc": "vite build --config vite.config.wc.ts"

Output: dist/tanstack-app.iife.js — a single file any host page can load:

<script src="tanstack-app.iife.js"></script>
<tanstack-app></tanstack-app>

Files to create / modify

FileActionReason
src/App.tsxCreateBody-level app (no html/head/body)
src/widget.tsxCreateCustom element definition + bootstrap
vite.config.wc.tsCreateLib build without SSR plugins
package.jsonModifyAdd build:wc script
src/router.tsxModifyAccept optional history param
src/routes/__root.tsxNo changeKept intact for SSR build
src/styles.cssNo changeImported via ?inline in WC entry

CSS strategy inside Shadow DOM

OptionHowTrade-off
Constructable Stylesheet (recommended)Bundle CSS as string via ?inline, inject via adoptedStyleSheetsClean isolation, no leakage
Light DOM (no Shadow DOM)Pass shadow: false to r2wcSimpler, but styles leak both ways

Result

The original TanStack Start SSR app remains fully functional. The WC build is an additive parallel output — same source, different entry and Vite config.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

ll-feishu-audio

飞书语音交互技能。支持语音消息自动识别、AI 处理、语音回复全流程。需要配置 FEISHU_APP_ID 和 FEISHU_APP_SECRET 环境变量。使用 faster-whisper 进行语音识别,Edge TTS 进行语音合成,自动转换 OPUS 格式并通过飞书发送。适用于飞书平台的语音对话场景。

Archived SourceRecently Updated
General

test_skill

import json import tkinter as tk from tkinter import messagebox, simpledialog

Archived SourceRecently Updated
General

51mee-resume-profile

简历画像。触发场景:用户要求生成候选人画像;用户想了解候选人的多维度标签和能力评估。

Archived SourceRecently Updated
General

51mee-resume-parse

简历解析。触发场景:用户上传简历文件要求解析、提取结构化信息。

Archived SourceRecently Updated