# @cpsoinos/vite-plugin-http2-proxy 中文文档

规范地址：https://npmcn.com/package/%40cpsoinos/vite-plugin-http2-proxy/

版本：0\.1\.0
npm 元数据更新时间：2024-02-24T20:44:23.453Z
中文译文更新时间：2026-11-10T21:37:48.101Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40cpsoinos/vite-plugin-http2-proxy
原文对照：https://npmcn.com/package/%40cpsoinos/vite-plugin-http2-proxy/?lang=original
项目主页：https://github.com/cpsoinos/vite-plugin-http2-proxy#readme
源码仓库：https://github.com/cpsoinos/vite-plugin-http2-proxy

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：10.3 kB，7 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2024-02-24T20:06:08.485Z
- 最新版本发布：2024-02-24T20:44:23.012Z
- 近 30 天下载量：22693（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

一个 Vite 插件,允许您向 HTTP2 服务器代理请求 .

## 安装

```sh
npm install @cpsoinos/vite-plugin-http2-proxy
```

也可以使用：`pnpm add @cpsoinos/vite-plugin-http2-proxy`、`yarn add @cpsoinos/vite-plugin-http2-proxy`、`bun add @cpsoinos/vite-plugin-http2-proxy`

## README

# 维特-插管- http2- 代用

与 Vite 在开发模式中运行 HTTP2 代理 。 配对时效果不错 [阴道插孔- mkcert](https://github.com/liuweiGL/vite-plugin-mkcert)。 。 。 .

## 我为什么要用这个?

当使用 Vite 内置代理和 `https: true`,所有请求被降级到HTTP1.1. 见 [这个问题](https://github.com/vitejs/vite/issues/4184) 讨论。 此插件在开发模式中需要代理请求到外部 API 时有用, 您想要使用 https 和/或 HTTP2.

用这个 [阴道插孔- mkcert](https://github.com/liuweiGL/vite-plugin-mkcert) 用于无缝的 SSL 证书生成和使用 https , 并在开发中使用代理用户.

## 安装

### 使用 `npm`

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

### 使用 `yarn`

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

### 使用 `pnpm`

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

## 使用量

```ts
// 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
          },
        },
      }),
    },
  }
})
```

## 核证

改编自 [属性](https://gist.github.com/xfournet/068592b3d1ddd488427b874b23f707bf) 由 @ xfournet 共享 [这个问题的评论](https://github.com/vitejs/vite/issues/4184#issuecomment-1824133940)。 。 。 .

此插件使用 `http2-proxy` 在引擎盖下。 见 [http2-正则](https://www.npmjs.com/package/http2-proxy) 用于获取更多信息的软件包.

## 显示您的支持

如果这个计划能帮助你的话,就给你一个!

## 许可证

版权 2024 [科里·普苏伊诺斯](https://github.com/cpsoinos)。 。 。 .

这个项目是 [麻省理工学院](https://github.com/cpsoinos/nuxt-svgo/blob/main/LICENSE) 有执照.

## 常见问题

### @cpsoinos/vite-plugin-http2-proxy 是什么？

一个 Vite 插件,允许您向 HTTP2 服务器代理请求 \.

### 如何安装 @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 和提交记录判断。

