Registry / devops / vite-plugin-h2-proxy

vite-plugin-h2-proxy

JSON →
library1.0.1jsnpmunverified

A Vite plugin that resolves the conflict between HTTP/2 and proxy in Vite dev server. Version 1.0.1, stable. It provides a drop-in replacement for Vite's built-in proxy configuration when using HTTP/2, with extended hooks like onReq, onRes, and onError. Compatible with Vite's proxy options except configure. Supports TypeScript types out of the box.

npm install vite-plugin-h2-proxy
INSTALL
IMPORT
SIG · VITE-PLUGIN-H2-PRO
V
vite-plugin-h2-proxy
devopsjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

vitePluginH2Proxy
import vitePluginH2Proxy from 'vite-plugin-h2-proxy'
import { vitePluginH2Proxy } from 'vite-plugin-h2-proxy'
Package uses default export, not named export.
ProxyOptions
import type { ProxyOptions } from 'vite-plugin-h2-proxy'
import { ProxyOptions } from 'vite-plugin-h2-proxy'
Use type import to avoid runtime bundle inclusion.
default export
const vitePluginH2Proxy = require('vite-plugin-h2-proxy')
const { vitePluginH2Proxy } = require('vite-plugin-h2-proxy')
CommonJS require gets the default export as a whole.

Demonstrates basic usage of vite-plugin-h2-proxy with http2 dev server, including custom proxy options and hooks.

import { defineConfig } from 'vite'; import vitePluginH2Proxy from 'vite-plugin-h2-proxy'; const proxyConfig = { target: 'http://localhost:8080', proxyTimeout: 5000, timeout: 5000, rewrite: (path) => path.replace(/^\/fallback/, ''), onReq(req, proxyReq) { proxyReq.headers.origin = 'http://localhost:8080'; }, onRes(req, res, proxyRes) { res.setHeader('set-cookie', proxyRes.headers['set-cookie'] + '; SameSite=None; Secure'); }, onError(error) { console.log(error); }, bypass() { return false; } }; export default defineConfig({ plugins: [vitePluginH2Proxy(proxyConfig)], });
Debug
Known issues
gotchaThe plugin replaces Vite's built-in proxy when using HTTP/2. If not using HTTP/2, use Vite's native proxy instead.
fix
Only use this plugin when Vite config has server.http2: true.
affects: >=0.0.0
deprecatedThe 'configure' option from Vite's proxy is not supported as per the plugin's compatible options.
fix
Use the provided hooks (onReq, onRes, onError) instead of configure.
affects: >=0.0.0
gotchaThe proxy configuration object is passed directly to the plugin, not under a 'proxy' key like Vite's native config.
fix
Use the plugin function with the config object and not inside the `server.proxy` field.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: vitePluginH2Proxy is not a function
Using named import instead of default import.
fix
Use `import vitePluginH2Proxy from 'vite-plugin-h2-proxy'` (without curly braces).
Error: [vite] http2-proxy: ...
Missing or misconfigured proxy target or other options.
fix
Ensure the proxy config has a valid `target` string and check other options.
Cannot find module 'vite-plugin-h2-proxy'
Package not installed or not added as dev dependency.
fix
Run `npm install -D vite-plugin-h2-proxy` or equivalent.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
vite-plugin-h2-proxy — npm install vite-plugin-h2-proxy · libregistry