Zero-Runtime Philosophy
Traditional API clients like Axios or Fetch wrappers often come with heavy runtimes. They need to handle:
- URL parsing and template replacement.
- Query parameter serialization.
- Request/Response transformation.
vRPC moves all of this to build time.
How it works
1. Development Mode
During development, vRPC uses a JavaScript Proxy. When you call api.getUser(), the proxy intercepts the call, looks up the metadata in rpc.map.ts, and executes a standard fetch.
This allows for a lightweight, zero-configuration setup that is fully typed.
2. Build Time (The AST Plugin)
When you run your production build (npm run build), the vRPC Bundler Plugin takes over. It performs an AST (Abstract Syntax Tree) transformation:
- It finds all calls to your vRPC clients (e.g.,
api.method()). - It looks up the static metadata for that specific method.
- It inlines the request configuration directly into the call site.
- It replaces the complex proxy call with a bare-bones production executor.
3. Production
In the final bundle, the vRPC runtime is completely stripped away. Your code essentially becomes:
javascript
// BEFORE (what you wrote)
const user = await api.getUser({ params: { id: '42' } })
// AFTER (what goes to the user)
const user = await __vrpc_exec('GET', '/users/42', { ... })The metadata, the proxy, and most of the library code never reach your users' browsers. This results in:
- Smaller bundle sizes.
- Faster execution (no proxy overhead).
- Zero dependency tree for the client.