@espcom/esbuild-plugin-compress

中文文档
1.2.0发布于 2025/06/07MITTypeScriptESM + CJS近 30 天下载 3579

npm coverage ![size-es

原始使用文档
文档目录5 节
  1. @espcom/esbuild-plugin-compress
  2. Installation
  3. Usage
  4. Options
  5. Compression Levels

@espcom/esbuild-plugin-compress

npm coverage size-esm size-cjs

An esbuild plugin that compresses your output files using gzip, brotli, or zstd compression algorithms.

Installation

You can install this plugin via npm:

npm install @espcom/esbuild-plugin-compress

Usage

To use the plugin, import it and add it to your esbuild configuration.

[!WARNING]
Make sure to set write: false in your esbuild configuration, so the plugin can handle file writing after compression.

import esbuild from 'esbuild';
import { pluginCompress } from '@espcom/esbuild-plugin-compress';

esbuild.build({
  entryPoints: ['app.js'],
  bundle: true,
  write: false, // important for now
  outfile: 'out.js',
  plugins: [
    pluginCompress({
      gzip: true,  // Enable gzip compression
      brotli: true,  // Enable brotli compression
      zstd: true,  // Enable zstd compression
      level: 'high',  // Compression level: low, high, max
      extensions: ['.js', '.css']  // File extensions to compress
    })
  ],
});

Options

The plugin accepts the following options:

  • gzip (boolean): Enable gzip compression.
  • brotli (boolean): Enable brotli compression.
  • zstd (boolean): Enable zstd compression.
  • level ('low' | 'high' | 'max'): Set the compression level (low, high, max). Default is max.
  • extensions (Array<'.js' | '.css' | '.svg' | '.json'>): File extensions to compress. Default is ['.js', '.css'].

Compression Levels

The plugin provides three compression levels:

  • low: Fastest compression with lower ratio.
  • high: Balanced compression ratio and speed.
  • max: Highest compression ratio, but slower.

版本与发布记录

@espcom/esbuild-plugin-compress 共发布 4 个版本,首次发布于 2024/09/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.0latest2025/06/071.4 年前
1.1.02024/10/172 年前
1.0.12024/09/212 年前
1.0.02024/09/192 年前

关于 @espcom/esbuild-plugin-compress 的常见问题

@espcom/esbuild-plugin-compress 是什么?

![size-es

如何安装 @espcom/esbuild-plugin-compress?

在项目目录运行 npm install @espcom/esbuild-plugin-compress,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:esbuild(>=0.23)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@espcom/esbuild-plugin-compress 支持 TypeScript 吗?

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

@espcom/esbuild-plugin-compress 支持 ESM 还是 CommonJS?

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

@espcom/esbuild-plugin-compress 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@espcom/esbuild-plugin-compress 可以商用吗?

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

@espcom/esbuild-plugin-compress 的下载量有多少?

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

@espcom/esbuild-plugin-compress 还在维护吗?

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