
Security News
TeamPCP Is Systematically Targeting Security Tools Across the OSS Ecosystem
TeamPCP is targeting security tools across the OSS ecosystem, turning scanners and CI pipelines into infostealers to access enterprise secrets.
@vitejs/devtools-rpc
Advanced tools
DevTools RPC for Vite, featuring extensible birpc interfaces with advanced type-safe function definitions.
valibotpnpm install @vitejs/devtools-rpc
import { createRpcClient } from '@vitejs/devtools-rpc/client'
import { createWsRpcPreset } from '@vitejs/devtools-rpc/presets/ws/client'
import { createRpcServer } from '@vitejs/devtools-rpc/server'
Use defineRpcFunction to create type-safe RPC function definitions:
import { defineRpcFunction } from '@vitejs/devtools-rpc'
// Simple function
const greet = defineRpcFunction({
name: 'greet',
handler: (name: string) => `Hello, ${name}!`
})
You can provide a context to functions for setup and initialization:
import { defineRpcFunction } from '@vitejs/devtools-rpc'
// With setup and context
const getUser = defineRpcFunction({
name: 'getUser',
setup: (context) => {
console.log(context)
return {
handler: (id: string) => context.users[id]
}
}
})
Use Valibot schemas for automatic argument and return value validation:
import { defineRpcFunction } from '@vitejs/devtools-rpc'
import * as v from 'valibot'
const add = defineRpcFunction({
name: 'add',
args: [v.number(), v.number()] as const,
returns: v.number(),
handler: (a, b) => a + b // Types are automatically inferred
})
RpcFunctionsCollector manages dynamic function registration and provides a type-safe proxy for accessing functions:
import { defineRpcFunction, RpcFunctionsCollectorBase } from '@vitejs/devtools-rpc'
// Provide a custom context to the collector
const collector = new RpcFunctionsCollectorBase({ users: [/* ... */] })
// Register functions
collector.register(defineRpcFunction({
name: 'greet',
handler: (name: string) => `Hello, ${name}!`,
}))
collector.register(defineRpcFunction({
name: 'getUser',
setup: (context) => {
return {
handler: (id: string) => context.users.find((user: { id: string }) => user.id === id)
}
}
}))
// Access via proxy
await collector.functions.greet('Alice') // "Hello, Alice!"
// Listen for changes
const unsubscribe = collector.onChanged((fnName) => {
console.log(`Function ${fnName} changed`)
})
The dump feature allows pre-computing RPC results for static hosting, testing, or offline mode. This is useful for static sites or when you want to avoid runtime computation.
import { createClientFromDump, defineRpcFunction, dumpFunctions } from '@vitejs/devtools-rpc'
// Define functions with dump configurations
const greet = defineRpcFunction({
name: 'greet',
handler: (name: string) => `Hello, ${name}!`,
dump: {
inputs: [
['Alice'],
['Bob'],
['Charlie']
],
fallback: 'Hello, stranger!'
}
})
// Collect pre-computed results
const store = await dumpFunctions([greet])
// Create a client that serves from the dump store
const client = createClientFromDump(store)
await client.greet('Alice') // Returns pre-computed: "Hello, Alice!"
await client.greet('Unknown') // Returns fallback: "Hello, stranger!"
Functions with type: 'static' automatically get dumped with empty arguments if no dump configuration is provided.
You can provide pre-computed records directly to bypass function execution:
import { defineRpcFunction } from '@vitejs/devtools-rpc'
const multiply = defineRpcFunction({
name: 'multiply',
handler: (a: number, b: number) => a * b,
dump: {
records: [
{ inputs: [2, 3], output: 6 },
{ inputs: [4, 5], output: 20 },
],
},
})
You can also mix computed (inputs) and pre-computed (records) in the same dump configuration.
Enable parallel processing for faster dump collection:
import { dumpFunctions } from '@vitejs/devtools-rpc'
// Enable parallel with default concurrency of 5
const store = await dumpFunctions([greet], context, {
concurrency: true
})
// Or specify a custom concurrency limit
const store = await dumpFunctions([greet], context, {
concurrency: 10 // Limit to 10 concurrent executions
})
Set concurrency to true for parallel execution (default limit: 5) or a number to specify the exact concurrency limit.
. - Type-safe function definitions and utilities (main export)
RpcFunctionsCollectorBase, defineRpcFunction, createDefineWrapperWithContextdumpFunctions, createClientFromDump, RpcCacheManager./client - RPC client
createRpcClient./server - RPC server
createRpcServer./presets - RPC presets
defineRpcClientPreset, defineRpcServerPreset./presets/ws/client - WebSocket client preset
createWsRpcPreset./presets/ws/server - WebSocket server preset
createWsRpcPresetSee src/examples and test files for complete integration examples.
MIT License © VoidZero Inc.
FAQs
Vite DevTools RPC Layer
The npm package @vitejs/devtools-rpc receives a total of 15,612 weekly downloads. As such, @vitejs/devtools-rpc popularity was classified as popular.
We found that @vitejs/devtools-rpc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
TeamPCP is targeting security tools across the OSS ecosystem, turning scanners and CI pipelines into infostealers to access enterprise secrets.

Security News
TypeScript 6.0 introduces new standard APIs, modern default settings, and deprecations as it prepares projects for the upcoming TypeScript 7.0 release.

Security News
/Research
Newly published Trivy Docker images (0.69.4, 0.69.5, and 0.69.6) were found to contain infostealer IOCs and were pushed to Docker Hub without corresponding GitHub releases.