Skip to content

Plugin for esbuild that compresses embedded data, which will be decompressed at runtime, to reduce bundle size.

License

Notifications You must be signed in to change notification settings

polyipseity/esbuild-compress

Repository files navigation

esbuild-compress

Plugin for esbuild that compresses embedded data, which will be decompressed at runtime, to reduce bundle size.

Usage

  • Configuration:
import { build } from "esbuild"
import esbuildCompress from "esbuild-compress"
import myBuildOptions from "./my-build-options.mjs"

await build({
	...myBuildOptions,
	plugins: [
		esbuildCompress({
			// see plugin options
			compressors: [
				{
					filter: /\.json$/u,
					loader: "json",
				},
				{
					filter: /\.txt$/u,
					lazy: true,
					loader: "text",
				},
			],
		}),
	],
})
  • Usage:
import json from "./example.json"
import text0 from "./example.txt"

const text = await text0 // unnecessary if `lazy` is `false`

consumeJSON(json.key)
consumeText(text)

About

Plugin for esbuild that compresses embedded data, which will be decompressed at runtime, to reduce bundle size.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published