@multiplatform.one/vite-plugin-vscode
v10.5.1
Published
Vite config factory for building a VS Code extension (extension host + Tamagui webview) as a target of a multiplatform.one One app — wraps @tomjs/vite-plugin-vscode with the workspace source aliases, the one-router seam alias, React dedupe against one's v
Readme
@multiplatform.one/vite-plugin-vscode
Vite config factory for building a VS Code extension (extension host +
Tamagui webview) as a target of a multiplatform.one One app. It wraps
@tomjs/vite-plugin-vscode in its recommended mode: tsdown builds the
extension host, vite builds the webview. The target lives inside the
product app, with the layout that mode expects:
<targetDir>/index.html (webview entry, vite root)
<targetDir>/extension/index.ts (extension host)
<targetDir>/webview/… (webview React sources, aliased as @)The build lands under outDir as extension/ + webview/.
writeVsceManifest then writes the extension-manifest package.json
next to them, so vsce package runs against that staging dir: the
product app's own package.json is an Expo/One manifest and can't
double as the extension's.
Exports
| export | what it is |
| ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| createVscodeConfig(options) | async; the vite UserConfig: React + the React Compiler preset, Tamagui extraction, @tomjs/vite-plugin-vscode, workspace source aliases, one → router seam |
| writeVsceManifest(stagingDir, manifest) | writes <stagingDir>/package.json (main defaults to extension/index.js, engines.vscode to ^1.75.0), then runs fixStagedWebviewAssetUris |
| fixStagedWebviewAssetUris(stagingDir) | rewrites the webview dist path baked into the extension-host bundle to "webview", so webview assets resolve from the staging dir |
| resolveSeamOneAdapter(workspaceRoot) | the seam's one-adapter: workspace source inside the monorepo, @multiplatform.one/router/seam otherwise |
| DEFAULT_WEBVIEW_CSP | the webview CSP meta used when csp is not passed; unlike the plugin's default it allows img-src and font-src |
Usage
// vite.config.vscode.ts
import { resolve } from "node:path";
import { createVscodeConfig } from "@multiplatform.one/vite-plugin-vscode";
import { defineConfig } from "vite";
export default defineConfig(async () =>
createVscodeConfig({
targetDir: resolve(import.meta.dirname, "vscode"),
outDir: resolve(import.meta.dirname, "dist-vscode"),
tamaguiConfig: resolve(import.meta.dirname, "config/tamagui.config.ts"),
}),
);Optional: workspaceRoot (defaults to the git toplevel), csp, isDev
(defaults to NODE_ENV !== "production"), define (merged over the
factory's defines) and aliases (appended after the factory's). After
vite build, a staging script calls
writeVsceManifest(outDir, { name, publisher, version, contributes, … }).
Required dependencies
Declared peers, install them next to this plugin:
| package | why |
| ------------------------------- | -------------------------------------------------------- |
| vite >=5 | the build tool itself |
| @tomjs/vite-plugin-vscode >=7 | extension-host and webview builds |
| @vitejs/plugin-react >=4 | webview build (React + the React Compiler preset) |
| @tamagui/vite-plugin | webview static extraction. Lazy-imported at factory call |
The factory aliases react, react-dom and the jsx runtimes to
<workspaceRoot>/node_modules/react*, so one's vendored React 18
never reaches the webview. Install both at the workspace root.
