Registry / devops / esbuild-compress

esbuild-compress

JSON →
library2.2.0jsnpmunverified

esbuild-compress is a plugin for esbuild that compresses embedded data at build time to reduce bundle size, with runtime decompression. Current stable version is 2.2.0. It supports various compression algorithms via configurable compressors, including lazy (async) decompression. Key differentiators: designed specifically for esbuild, supports both sync and async decompression, and works with multiple data formats (JSON, text, etc.). Released under MIT license.

npm install esbuild-compress
INSTALL
IMPORT
SIG · ESBUILD-COMPRESS
E
esbuild-compress
devopsjavascriptv2.2.0
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.

default
import esbuildCompress from 'esbuild-compress'
const esbuildCompress = require('esbuild-compress')
ESM-only package; CommonJS require is not supported.
esbuildCompress
import esbuildCompress from 'esbuild-compress'
import { esbuildCompress } from 'esbuild-compress'
Package uses default export only; named import will yield undefined.
Plugin type (TypeScript)
import type { Plugin } from 'esbuild'; import esbuildCompress from 'esbuild-compress'
import { Plugin } from 'esbuild-compress'
Plugin type is from esbuild, not from esbuild-compress.

Shows basic usage of esbuild-compress plugin with two compressors: one for JSON files (sync) and one for text files (lazy/async).

import { build } from 'esbuild'; import esbuildCompress from 'esbuild-compress'; await build({ entryPoints: ['input.js'], outfile: 'output.js', bundle: true, plugins: [ esbuildCompress({ compressors: [ { filter: /\.json$/, loader: 'json' }, { filter: /\.txt$/, lazy: true, loader: 'text' }, ], }), ], });
Debug
Known issues
breakingRequires esbuild >=0.17.0 due to plugin API changes.
fix
Upgrade esbuild to version 0.17.0 or higher.
affects: <0.17.0
gotchaThe 'lazy' option makes decompression async; importing without await will return a Promise.
fix
Use await when importing lazy-compressed modules: const data = await import('./file.txt') (if using dynamic imports) or access the default export and await if using static imports with lazy loader.
affects: >=0.0.0
breakingVersion 2.x dropped support for CommonJS (require).
fix
Switch to ESM imports (import).
affects: >=2.0.0
Errors
Common errors & fixes
Error: Cannot find module 'esbuild-compress'
Package not installed or not in node_modules.
fix
Run npm install esbuild-compress --save-dev
TypeError: esbuildCompress is not a function
Using named import instead of default import.
fix
Change to 'import esbuildCompress from "esbuild-compress"'
error: [plugin esbuild-compress] Cannot find module 'iltorb'
Missing optional dependency for brotli compression.
fix
Install iltorb if needed: npm install iltorb
SyntaxError: Cannot use import statement outside a module
Using ESM syntax in a CommonJS project without type: module.
fix
Add "type": "module" to package.json or use .mjs extension.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
esbuildrequiredpeer dependency required for plugin to function
Agent activity
2 hits · last 30 days
node
2
Resources