@cpsoinos/vite-plugin-http2-proxy

中文文档
0.1.0发布于 2024/02/25MITTypeScriptESM + CJS近 30 天下载 2.3万

A Vite plugin that allows you to proxy requests to an HTTP2 server.

原始使用文档
文档目录9 节
  1. Why would I use this?
  2. Install
  3. Using npm
  4. Using yarn
  5. Using pnpm
  6. Usage
  7. Accreditations
  8. Show your support
  9. 📝 License

vite-plugin-http2-proxy

Run an HTTP2 proxy in development mode with Vite. Works great when paired with vite-plugin-mkcert.

Why would I use this?

When using Vite's built-in proxy and https: true, all requests are downgraded to HTTP1.1. See this issue for discussion. This plugin is useful when you need to proxy requests to an external API in development mode and you want to use https and/or HTTP2.

Use this with vite-plugin-mkcert for seamless SSL certificate generation and use of https with proxy usage in development.

Install

Using npm

npm install @cpsoinos/vite-plugin-http2-proxy --save-dev

Using yarn

yarn add @cpsoinos/vite-plugin-http2-proxy -D

Using pnpm

pnpm add @cpsoinos/vite-plugin-http2-proxy -D

Usage

// vite.config.ts

import { defineConfig } from 'vite'
import http2Proxy from '@cpsoinos/vite-plugin-http2-proxy'
import mkcert from 'vite-plugin-mkcert' // optional - use to generate SSL certificates and use https in development

export default defineConfig(({ mode }) => {
  return {
    plugins: [
      // ... other plugins
      mkcert(), // optional
      http2Proxy({ quiet: true }), // optional -- suppress error logging
    ],
    server: {
      // optional - only in development mode
      ...(mode === 'development' && {
        proxy: {
          '/api': {
            target: 'https://api.example.com',
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/api/, ''), // optional - remove `/api` from request path
          },
        },
      }),
    },
  }
})

Accreditations

Adapted from a gist shared by @xfournet in this issue comment.

This plugin uses http2-proxy under the hood. See the http2-proxy package for more information.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2024 Corey Psoinos.

This project is MIT licensed.

版本与发布记录

@cpsoinos/vite-plugin-http2-proxy 共发布 2 个版本,首次发布于 2024/02/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.0latest2024/02/252 年前
0.0.12024/02/252 年前

关于 @cpsoinos/vite-plugin-http2-proxy 的常见问题

@cpsoinos/vite-plugin-http2-proxy 是什么?

A Vite plugin that allows you to proxy requests to an HTTP2 server.

如何安装 @cpsoinos/vite-plugin-http2-proxy?

在项目目录运行 npm install @cpsoinos/vite-plugin-http2-proxy,或使用 pnpm add / yarn add / bun add。

@cpsoinos/vite-plugin-http2-proxy 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cpsoinos/vite-plugin-http2-proxy 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cpsoinos/vite-plugin-http2-proxy 可以商用吗?

@cpsoinos/vite-plugin-http2-proxy 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cpsoinos/vite-plugin-http2-proxy 的下载量有多少?

根据 npm 官方下载统计,@cpsoinos/vite-plugin-http2-proxy 在 2026/10/11 – 2026/11/09 这 30 天内被下载 22,693 次,日均约 756 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cpsoinos/vite-plugin-http2-proxy 还在维护吗?

最新版本 0.1.0 发布于 2024/02/25(2 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/02/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。