-
-
Notifications
You must be signed in to change notification settings - Fork 245
feat: Vite 8 support via vite-plugin-inspect v12 and devtools-kit RPC #1085
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import { debounce } from 'perfect-debounce' | |
| import { RpcFunctionCtx } from './types' | ||
|
|
||
| export function getGraphFunctions(ctx: RpcFunctionCtx) { | ||
| const { rpc, server } = ctx | ||
| const { getRpc, server } = ctx | ||
| const debouncedModuleUpdated = debounce(() => { | ||
| getViteRpcServer<ViteRPCFunctions>?.()?.broadcast?.emit('graphModuleUpdated') | ||
| }, 100) | ||
|
|
@@ -15,10 +15,11 @@ export function getGraphFunctions(ctx: RpcFunctionCtx) { | |
| }) | ||
| return { | ||
| async getGraphModules(): Promise<ModuleInfo[]> { | ||
| const meta = await rpc.getMetadata() | ||
| const rpc = getRpc() | ||
| const meta = await rpc?.invokeLocal('vite-plugin-inspect:get-metadata' as any) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not aware of a good way to type these calls to |
||
| const modules = ( | ||
| meta | ||
| ? await rpc.getModulesList({ | ||
| ? await rpc?.invokeLocal('vite-plugin-inspect:get-modules-list' as any, { | ||
| vite: meta?.instances[0].vite, | ||
| env: meta?.instances[0].environments[0], | ||
| }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import type { RpcFunctionsHost } from '@vitejs/devtools-kit' | ||
| import { ResolvedConfig, ViteDevServer } from 'vite' | ||
| import { ViteInspectAPI } from 'vite-plugin-inspect/index' | ||
|
|
||
| export interface RpcFunctionCtx { | ||
| rpc: ViteInspectAPI['rpc'] | ||
| getRpc: () => RpcFunctionsHost | undefined | ||
| server: ViteDevServer | ||
| config: ResolvedConfig | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| import type { DevToolsNodeContext, RpcFunctionsHost } from '@vitejs/devtools-kit' | ||
| import type { PluginOption, ResolvedConfig, ViteDevServer } from 'vite' | ||
| import type { VitePluginInspectorOptions } from 'vite-plugin-vue-inspector' | ||
| import fs from 'node:fs' | ||
| import path from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
| import { DevTools as ViteDevTools } from '@vitejs/devtools' | ||
| import { createViteServerRpc } from '@vue/devtools-core' | ||
| import { setViteServerContext } from '@vue/devtools-kit' | ||
| import { bold, cyan, dim, green, yellow } from 'kolorist' | ||
|
|
@@ -89,6 +91,7 @@ export default function VitePluginVueDevTools(options?: VitePluginVueDevToolsOpt | |
| const pluginOptions = mergeOptions(options ?? {}) | ||
|
|
||
| let config: ResolvedConfig | ||
| let rpc: RpcFunctionsHost | undefined | ||
|
|
||
| function configureServer(server: ViteDevServer) { | ||
| const base = (server.config.base) || '/' | ||
|
|
@@ -110,9 +113,11 @@ export default function VitePluginVueDevTools(options?: VitePluginVueDevToolsOpt | |
| setViteServerContext(server) | ||
|
|
||
| const rpcFunctions = getRpcFunctions({ | ||
| rpc: inspect.api.rpc, | ||
| server, | ||
| config, | ||
| getRpc() { | ||
| return rpc | ||
| }, | ||
| }) | ||
| createViteServerRpc(rpcFunctions) | ||
|
|
||
|
|
@@ -145,6 +150,11 @@ export default function VitePluginVueDevTools(options?: VitePluginVueDevToolsOpt | |
| configureServer(server) { | ||
| configureServer(server) | ||
| }, | ||
| devtools: { | ||
| setup(ctx: DevToolsNodeContext) { | ||
| rpc = ctx.rpc | ||
| }, | ||
| }, | ||
| async resolveId(importee: string) { | ||
| if (importee === devtoolsOptionsImportee) { | ||
| return resolvedDevtoolsOptions | ||
|
|
@@ -216,6 +226,7 @@ export default function VitePluginVueDevTools(options?: VitePluginVueDevToolsOpt | |
| } | ||
|
|
||
| return [ | ||
| ViteDevTools(), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a hack and definitely not right. I'm using It'll also fail if something else adds another copy of the Vite DevTools plugin. |
||
| inspect as PluginOption, | ||
| pluginOptions.componentInspector && VueInspector({ | ||
| toggleComboKey: '', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this playground to test my changes.
I had to remove
vite-plugin-inspectfrom the plugins because it caused an error:We're already adding another copy of
vite-plugin-inspectinside Vue DevTools, and it seems that v12.0.0-beta.1 isn't happy with that duplication.As a side note, running the playground using
pnpm run playfrom the project root proved problematic becauseturbodidn't play nicely with the authentication stuff in Vite DevTools. I had to runpnpm run devfrompackages/playground/basicinstead.