AI TOOLS

Share a shadcn/ui component as a link

Code that imports from "@/components/ui/button" needs a project around it before it runs. Build it with Vite into one HTML file, upload the file and send the link. Here is the setup that was tested and the two errors you will likely hit.

4 min read·

shadcn/ui is a set of React components styled with Tailwind CSS. AI tools use it often for dashboards, forms and pricing pages. The generated code imports components from paths such as "@/components/ui/button" and "@/lib/utils", which are files in your project, not packages on a CDN.

So a shadcn component cannot be pasted into a bare HTML file the way a plain React component can. Build it once with Vite into a single HTML file, then share that file.

The setup

Five steps, once per project:

  • ✓Start a Vite React project (npm create vite@latest, React template) and add Tailwind with the @tailwindcss/vite plugin.
  • ✓Run npx shadcn@latest init, then npx shadcn@latest add for each component the code imports, such as button or card. This writes the component files, lib/utils and the theme variables in your CSS file.
  • ✓Paste the generated component into src/App.tsx.
  • ✓Install the plugin that inlines everything: npm install -D vite-plugin-singlefile. Add viteSingleFile() to the plugins in vite.config.ts, after react() and tailwindcss().
  • ✓Run npm run build. dist/index.html is the whole app: JavaScript, CSS and icons in one file.

What was tested

Built with Vite 6.4, Tailwind 4.3, vite-plugin-singlefile 2.3 and React 18.3, with a shadcn-style Button using class-variance-authority, @radix-ui/react-slot and a lucide-react icon. The output was one 188 KB index.html (60 KB gzipped). Opened in Chrome from a local file, the default button rendered with the theme colors, the outline button showed its border, the icon drew and clicking updated the count.

If the build fails or the page looks wrong

Both were reproduced:

  • ✓The build stops with Rollup failed to resolve import "@/components/ui/button": vite.config.ts has no alias for @. Add resolve: { alias: { "@": path.resolve(import.meta.dirname, "./src") } } and import path from "node:path". The shadcn CLI also expects the matching "paths" entry in tsconfig.
  • ✓Buttons have no background and plain black text: the CSS file is missing the theme variables (--primary, --primary-foreground, --border and the rest) and the @theme block that maps them to Tailwind colors. Run npx shadcn@latest init again or copy the variables from the shadcn docs into src/index.css.
  • ✓If the page is blank, open the browser console. A missing package shows up there by name; install it and build again.

Upload it and send the link

Drag dist/index.html onto the FileShare Pro dashboard and copy the link. Viewers need no account.

Turn on comments and reviewers can pin notes to parts of the page after typing a name. When you change the component, build again and upload the new file over the old one; the link stays the same: updating a shared link without changing it.

Related: sharing a Vite app as a single HTML file and sharing a Tailwind CSS page as a link.

Frequently asked

Can I skip the build step?

Not with code that imports from "@/components/ui/...". Those files only exist in a project. For a component that imports only React and npm packages, the no-build route works: share a React component as a link.

Does the built file need a server?

No. Everything is inside the one HTML file, so it runs from any static link, or from a double-click on your computer.

Is it free?

Yes. The free plan hosts up to 50 files of up to 100 MB each, with view counts and comments included. Password-protected links are on Pro.

Got a page to share?

Drop the file, copy the link — live in seconds, free plan included.

Start sharing free