Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Parsec React Webview

A modern VSCode extension template for building React-powered webviews with Vite, Tailwind CSS, and shadcn/ui.

English | δΈ­ζ–‡

Features

  • πŸš€ Fast Development - Vite with Hot Module Replacement (HMR)
  • βš›οΈ React 19 - Build modern UIs with the latest React
  • 🎨 shadcn/ui - Beautiful, accessible components built on Radix UI
  • 🎯 Tailwind CSS v4 - Utility-first CSS framework
  • πŸ”„ RPC Communication - Type-safe communication between webview and extension host
  • πŸ“¦ TypeScript - Full type safety across the entire codebase
  • πŸ”’ Secure CSP - Content Security Policy for both dev and production
  • πŸ› οΈ ESLint + Prettier - Code quality and formatting
  • 🐢 Husky + lint-staged - Git hooks for automated checks

Project Structure

β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ extension.ts              # Extension entry point
β”‚   β”œβ”€β”€ getWebviewContent.ts      # Webview HTML generation (dev/prod)
β”‚   β”œβ”€β”€ router.ts                 # RPC router definitions
β”‚   └── webview/                  # React webview source
β”‚       β”œβ”€β”€ main.tsx              # React entry point
β”‚       β”œβ”€β”€ App.tsx               # Main React component
β”‚       β”œβ”€β”€ index.css             # Global styles & Tailwind config
β”‚       β”œβ”€β”€ components/           # React components
β”‚       β”‚   └── ui/               # shadcn/ui components
β”‚       β”œβ”€β”€ context/              # React contexts
β”‚       β”œβ”€β”€ lib/                  # Utility functions
β”‚       └── assets/               # Static assets
β”œβ”€β”€ assets/                       # Extension assets (icons)
β”œβ”€β”€ dist/                         # Build output
β”‚   β”œβ”€β”€ extension.js              # Bundled extension
β”‚   └── webview/                  # Built webview
β”œβ”€β”€ esbuild.config.mjs            # Extension bundler config
β”œβ”€β”€ vite.config.ts                # Webview bundler config
β”œβ”€β”€ tsconfig.json                 # Extension TypeScript config
β”œβ”€β”€ tsconfig.webview.json         # Webview TypeScript config
β”œβ”€β”€ components.json               # shadcn/ui configuration
└── package.json                  # Project manifest

Getting Started

Prerequisites

  • Node.js v18+
  • Visual Studio Code
  • Git

Installation

# Clone the repository
git clone <repository-url>
cd parsec-react-webview

# Install dependencies
npm install

# Initialize Husky (git hooks)
npx husky init

Development

  1. Start the Vite dev server:

    npm run dev:webview
  2. Launch the extension in VSCode:

    • Press F5 to open Extension Development Host
    • Click the πŸ’¬ icon in the activity bar
  3. Start coding:

    • Edit files in src/webview/
    • Changes will hot-reload automatically

Build

# Build webview
npm run build:webview

# Build extension
npm run build

# Build both (for packaging)
npm run vscode:prepublish

Package

# Package as .vsix
npm run package

# Install in VSCode
code --install-extension parsec-react-webview-*.vsix

Available Scripts

Script Description
npm run dev:webview Start Vite dev server with HMR
npm run build:webview Build webview for production
npm run build Build extension with esbuild
npm run compile TypeScript type checking
npm run lint Run ESLint
npm run format Format code with Prettier
npm run format:check Check code formatting
npm run package Package as .vsix file
npm run watch Watch mode for extension

Architecture

Extension Host (Node.js)

  • src/extension.ts - Registers the webview provider and commands
  • src/router.ts - Defines RPC procedures callable from the webview
  • src/getWebviewContent.ts - Generates HTML for dev/prod modes

Webview (React)

  • src/webview/main.tsx - React entry point with providers
  • src/webview/App.tsx - Main application component
  • src/webview/wrpc.ts - RPC client configuration

Communication

The webview communicates with the extension host via @webview-rpc:

// Webview (src/webview/wrpc.ts)
export const wrpc = withReactQuery<AppRouter>(createWrpcClient<AppRouter>());

// Usage in components
const { data } = wrpc.useQuery('getWorkspaceName');
const mutation = wrpc.useMutation('showAlert');
// Extension Host (src/router.ts)
export const appRouter = router({
  getWorkspaceName: procedure.resolve(() => {
    return vscode.workspace.name || 'No workspace open';
  }),
  showAlert: procedure.input(z.string()).resolve(({ input }) => {
    vscode.window.showInformationMessage(input);
    return true;
  }),
});

Configuration

shadcn/ui

Components are configured in components.json:

{
  "style": "base-maia",
  "rsc": false,
  "tsx": true,
  "tailwind": {
    "css": "src/webview/index.css",
    "baseColor": "neutral",
    "cssVariables": true
  },
  "aliases": {
    "components": "@/webview/components",
    "ui": "@/webview/components/ui",
    "lib": "@/webview/lib",
    "utils": "@/webview/lib/utils"
  }
}

Add components:

npx shadcn@latest add button
npx shadcn@latest add card

Tailwind CSS

Theme colors are defined in src/webview/index.css using CSS variables:

:root {
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  /* ... */
}

.dark {
  --primary: oklch(0.922 0 0);
  --primary-foreground: oklch(0.205 0 0);
  /* ... */
}

Path Aliases

Configured in tsconfig.json and vite.config.ts:

{
  "paths": {
    "@/*": ["./src/*"]
  }
}

Usage:

import { Button } from '@/webview/components/ui/button';
import { cn } from '@/webview/lib/utils';

Code Quality

ESLint + Prettier

# Check for issues
npm run lint

# Format code
npm run format

Git Hooks

Husky runs lint-staged on pre-commit:

  • *.{ts,tsx} β†’ ESLint fix + Prettier format
  • *.{json,css,md} β†’ Prettier format

Security

  • Content Security Policy (CSP) configured for both dev and production
  • Scripts are nonce-protected in production
  • Dev server connections are restricted to localhost

Technologies

License

MIT

About

A modern VSCode extension template for building React-powered webviews with Vite, Tailwind CSS, and shadcn/ui.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages