How to use React with a VSCode webview.
dev.to·5h·
Discuss: DEV
Flag this post

TL;DR: Turn VSCode Webviews into complex React apps with hot reload in development and a secure bundle-based setup in production.

What you’ll build

  • A VS Code extension whose Webview is a React + TypeScript app.
  • HMR (Fast Refresh) in development via Vite.
  • A Content Security Policy (CSP) safe production build.

Table of contents

  1. Scaffold the extension
  2. Create the React app
  3. Fix TS project boundaries
  4. Wire up the Webview panel
  5. Processing the Vite generated HTML
  6. Vite configuration
  7. Run in development
  8. Build & publish
  9. What’s next
  10. Github Implementation

Scaffold the extension

First install yeoman and the VS Code extension generator:

npm install --global yo generator-code
yo...

Similar Posts

Loading similar posts...