Skip to content

Latest commit

 

History

History
44 lines (37 loc) · 810 Bytes

README.md

File metadata and controls

44 lines (37 loc) · 810 Bytes

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)