-
Notifications
You must be signed in to change notification settings - Fork 39
Add React webview system with pnpm workspaces #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c461ed
Add React webview system with pnpm workspaces
EhabY b3d7825
Refactoring and moving things around
EhabY 22d849c
Share types between the extension and the webviews
EhabY ce14bb1
Simplify the CONTRIBUTING.md webview section
EhabY fa36b0c
Refactor webview packages and improve build setup
EhabY File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "@repo/tasks", | ||
| "version": "1.0.0", | ||
| "description": "Coder Tasks webview panel", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "tsc -b && vite build", | ||
| "dev": "vite build --watch" | ||
| }, | ||
| "dependencies": { | ||
| "@repo/webview-shared": "workspace:*", | ||
| "@vscode-elements/react-elements": "^2.4.0", | ||
| "react": "^19.0.0", | ||
| "react-dom": "^19.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^19.0.0", | ||
| "@types/react-dom": "^19.0.0", | ||
| "@vitejs/plugin-react-swc": "^3.8.0", | ||
| "typescript": "^5.7.3", | ||
| "vite": "^6.0.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { postMessage, useMessage } from "@repo/webview-shared/react"; | ||
| import { | ||
| VscodeButton, | ||
| VscodeProgressRing, | ||
| } from "@vscode-elements/react-elements"; | ||
| import { useCallback, useEffect, useState } from "react"; | ||
|
|
||
| import type { WebviewMessage } from "@repo/webview-shared"; | ||
|
|
||
| export default function App() { | ||
| const [ready, setReady] = useState(false); | ||
|
|
||
| const handleMessage = useCallback((message: WebviewMessage) => { | ||
| switch (message.type) { | ||
| case "init": | ||
| setReady(true); | ||
| break; | ||
| } | ||
| }, []); | ||
|
|
||
| useMessage(handleMessage); | ||
|
|
||
| useEffect(() => { | ||
| postMessage({ type: "ready" }); | ||
| }, []); | ||
|
|
||
| if (!ready) { | ||
| return <VscodeProgressRing />; | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <h2>Coder Tasks</h2> | ||
| <VscodeButton onClick={() => postMessage({ type: "refresh" })}> | ||
| Refresh | ||
| </VscodeButton> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /* Webview styles */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { StrictMode } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
|
|
||
| import App from "./App"; | ||
| import "./index.css"; | ||
|
|
||
| const root = document.getElementById("root"); | ||
| if (root) { | ||
| createRoot(root).render( | ||
| <StrictMode> | ||
| <App /> | ||
| </StrictMode>, | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "../tsconfig.webview.json", | ||
| "compilerOptions": { | ||
| "paths": { | ||
| "@repo/webview-shared": ["../webview-shared/src"] | ||
| } | ||
| }, | ||
| "include": ["src"], | ||
| "references": [{ "path": "../webview-shared" }] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { createWebviewConfig } from "../webview-shared/createWebviewConfig"; | ||
|
|
||
| export default createWebviewConfig("tasks", __dirname); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "extends": "@tsconfig/node20/tsconfig.json", | ||
| "compilerOptions": { | ||
| "lib": ["ES2023", "DOM", "DOM.Iterable"], | ||
| "module": "ESNext", | ||
| "moduleResolution": "bundler", | ||
| "jsx": "react-jsx", | ||
| "noEmit": true, | ||
| "noFallthroughCasesInSwitch": true, | ||
| "noImplicitOverride": true, | ||
| "noImplicitReturns": true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import react from "@vitejs/plugin-react-swc"; | ||
| import { resolve } from "node:path"; | ||
| import { defineConfig, type UserConfig } from "vite"; | ||
|
|
||
| /** | ||
| * Create a Vite config for a webview package | ||
| * @param webviewName - Name of the webview (used for output path) | ||
| * @param dirname - __dirname of the calling config file | ||
| */ | ||
| export function createWebviewConfig( | ||
| webviewName: string, | ||
| dirname: string, | ||
| ): UserConfig { | ||
| const production = process.env.NODE_ENV === "production"; | ||
|
|
||
| return defineConfig({ | ||
| plugins: [react()], | ||
| build: { | ||
| outDir: resolve(dirname, `../../dist/webviews/${webviewName}`), | ||
| emptyOutDir: true, | ||
| // Target modern browsers (VS Code webview uses Chromium from Electron) | ||
| target: "esnext", | ||
| // Skip gzip size calculation for faster builds | ||
| reportCompressedSize: false, | ||
| rollupOptions: { | ||
| // HTML is generated by the extension with CSP headers | ||
| input: resolve(dirname, "src/index.tsx"), | ||
| output: { | ||
| entryFileNames: "index.js", | ||
| assetFileNames: "index.[ext]", | ||
| }, | ||
| }, | ||
| // Keeps extension size down; build locally to map stack traces | ||
| sourcemap: !production, | ||
| }, | ||
| resolve: { | ||
| alias: { | ||
| "@repo/webview-shared": resolve(dirname, "../webview-shared/src"), | ||
| }, | ||
| }, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Types exposed to the extension (react/ subpath is excluded). | ||
| export type { WebviewMessage } from "./src/index"; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.