Skip to main content
doc0blade47/honodocumentation home
Sign in

Presets and Builds

Last updated Oct 12, 202688% grounded
Relevant source files

The following files were used as context for generating this wiki page:

Overview

The presets and builds system provides specialized distribution bundles, entry points, and routing optimizations tailored for different runtime performance characteristics and footprint constraints. Hono delivers standard functionality through its core router composition while offering lightweight distribution presets such as [[Application Core]] routing alternatives, package export mappings across package.json and jsr.json, and automated bundle size auditing harnesses [src/preset/quick.ts:1-23, [package.json:37-67, [src/preset/tiny.ts:1-19, [jsr.json:8-106, perf-measures/bundle-check/scripts/check-bundle-size.ts:1-50. Sources: src/preset/quick.ts:1-23, package.json:37-67, src/preset/tiny.ts:1-19, jsr.json:8-106, perf-measures/bundle-check/scripts/check-bundle-size.ts:1-50

Preset Architecture and Entry Points

Specialized Distribution Entry Points

Hono exposes multiple public distribution entry points designed for different runtime environments, bundle size thresholds, and routing performance profiles. The standard entry point at . resolves to the main package distribution, while specialized preset modules such as [[Application Core]] routing bundles target restricted environments package.json:37-67, jsr.json:8-106.

Hono organizes its distribution bundles across standard CommonJS, ESM, and type definition outputs defined in package.json and registry manifests in jsr.json. Consumers can import specialized presets directly from subpaths such as ./quick and ./tiny to optimize their application build output package.json:37-67, jsr.json:8-106.

Export SubpathType DefinitionsESM OutputCommonJS OutputPreset Purpose
../dist/types/index.d.ts./dist/index.js./dist/cjs/index.jsStandard multi-router entry point
./quick./dist/types/preset/quick.d.ts./dist/preset/quick.js./dist/cjs/preset/quick.js[[Application Core]] with SmartRouter (Linear + Trie)
./tiny./dist/types/preset/tiny.d.ts./dist/preset/tiny.js./dist/cjs/preset/tiny.js[[Application Core]] with lightweight PatternRouter

Sources: package.json:37-67, jsr.json:8-106

Architectural Trade-Offs

The standard package entry point imports from ./hono, allowing developers to leverage comprehensive feature sets across middlewares and helpers src/index.ts:17-53. In contrast, specialized presets bypass default router selections by extending HonoBase directly with targeted routing engines src/preset/quick.ts:6-23, src/preset/tiny.ts:6-19.

Note

The hono/quick preset initializes a SmartRouter composed of LinearRouter and TrieRouter instances, whereas hono/tiny instantiates a single PatternRouter to minimize initialization overhead src/preset/quick.ts:20-22, src/preset/tiny.ts:18-18.

Sources: src/preset/quick.ts:6-23, src/preset/tiny.ts:6-19, src/index.ts:17-53

Quick Preset Router Composition

Smart Router Initialization and Composition

The hono/quick preset constructs an optimized subclass of [[Application Core]] by extending HonoBase and instantiating a SmartRouter within its constructor src/preset/quick.ts:13-23. Rather than binding to a single routing strategy, SmartRouter receives an array containing both a LinearRouter and a TrieRouter instance src/preset/quick.ts:20-22.

export class Hono<
  E extends Env = BlankEnv,
  S extends Schema = BlankSchema,
  BasePath extends string = '/',
> extends HonoBase<E, S, BasePath> {
  constructor(options: HonoOptions<E> = {}) {
    super(options)
    this.router = new SmartRouter({
      routers: [new LinearRouter(), new TrieRouter()],
    })
  }

Sources: src/preset/quick.ts:13-23

Note

The hono/quick preset relies on module resolution from ../router/linear-router, ../router/smart-router, and ../router/trie-router to assemble its multi-strategy matching engine src/preset/quick.ts:8-10.

Sources: src/preset/quick.ts:8-10

Fallback Mechanics and Execution Flow

Component ClassImport PathRole in SmartRouter Composition
LinearRouter../router/linear-routerFast linear scanning for simpler route tables src/preset/quick.ts:8, src/preset/quick.ts:21
TrieRouter../router/trie-routerPrefix tree matching for complex parameter patterns src/preset/quick.ts:10, src/preset/quick.ts:21
SmartRouter../router/smart-routerComposite wrapper managing router selection and fallback src/preset/quick.ts:9, src/preset/quick.ts:20-22

Sources: src/preset/quick.ts:8-10, src/preset/quick.ts:20-22

Tiny Preset for Constrained Runtimes

Pattern-Based Dispatch Mechanics

The hono/tiny preset configures a minimal application footprint by extending HonoBase with the lightweight PatternRouter engine src/preset/tiny.ts:6-19. Instantiating Hono within this module assigns a PatternRouter directly to this.router, omitting complex multi-router selection logic and reducing overall binary weight for constrained execution environments src/preset/tiny.ts:16-19.

export class Hono<
  E extends Env = BlankEnv,
  S extends Schema = BlankSchema,
  BasePath extends string = '/',
> extends HonoBase<E, S, BasePath> {
  constructor(options: HonoOptions<E> = {}) {
    super(options)
    this.router = new PatternRouter()
  }
}

Sources: src/preset/tiny.ts:11-20]

Note

The hono/tiny implementation accepts generic type parameters for environment bindings (Env), schema validation (Schema), and base path prefixes (BasePath), passing options directly to the HonoBase superclass constructor src/preset/tiny.ts:11-17.

Sources: src/preset/tiny.ts:11-17

Class and Type Configuration

Exported SymbolSource PathType Definition / Role
Honosrc/preset/tiny.tsSubclass of HonoBase enforcing PatternRouter src/preset/tiny.ts:6-19
HonoBase../hono-baseCore routing and middleware execution engine src/preset/tiny.ts:6, src/preset/tiny.ts:15
PatternRouter../router/pattern-routerLightweight pattern-matching router backend src/preset/tiny.ts:8, src/preset/tiny.ts:18
HonoOptions../hono-baseConfiguration options interface for instantiation src/preset/tiny.ts:7, src/preset/tiny.ts:16

Sources: src/preset/tiny.ts:6-19]

Package Export Maps and Module Resolution

Node.js Package Configuration and Conditional Exports

The package.json file establishes dual CommonJS and ES Module distribution channels alongside TypeScript declaration mappings package.json:5-8, package.json:37-42. The root export configuration maps types, ESM imports, and CommonJS requires for core modules, presets, middleware, helpers, and utilities package.json:37-144.

Export KeyTypes PathImport Path (ESM)Require Path (CJS)
../dist/types/index.d.ts package.json:39./dist/index.js package.json:40./dist/cjs/index.js package.json:41
./request./dist/types/request.d.ts package.json:44./dist/request.js package.json:45./dist/cjs/request.js package.json:46
./tiny./dist/types/preset/tiny.d.ts package.json:59./dist/preset/tiny.js package.json:60./dist/cjs/preset/tiny.js package.json:61
./quick./dist/types/preset/quick.d.ts package.json:64./dist/preset/quick.js package.json:65./dist/cjs/preset/quick.js package.json:66
./compress./dist/types/middleware/compress/index.d.ts package.json:114./dist/middleware/compress/index.js package.json:115./dist/cjs/middleware/compress/index.js package.json:116

Sources: package.json:37-117

Note

The postbuild script executes publint to validate export map correctness, and copies package.cjs.json into distribution subdirectories to enforce CommonJS resolution boundaries package.json:28-30.

Sources: package.json:28-30

JSR and Deno Module Resolution

The jsr.json manifest defines direct TypeScript source mappings for JSR distribution, targeting Deno and modern edge runtimes jsr.json:1-106. It enables the sloppy-imports unstable flag and specifies compiler options tailored for DOM and Deno namespaces jsr.json:4-7.

"exports": {
  ".": "./src/index.ts",
  "./request": "./src/request.ts",
  "./types": "./src/types.ts",
  "./hono-base": "./src/hono-base.ts",
  "./tiny": "./src/preset/tiny.ts",
  "./quick": "./src/preset/quick.ts",
  "./http-exception": "./src/http-exception.ts",
  "./basic-auth": "./src/middleware/basic-auth/index.ts",
  "./bearer-auth": "./src/middleware/bearer-auth/index.ts",
  "./body-limit": "./src/middleware/body-limit/index.ts",
  "./ip-restriction": "./src/middleware/ip-restriction/index.ts",
  "./cache": "./src/middleware/cache/index.ts",
  "./route": "./src/helper/route/index.ts",
  "./cookie": "./src/helper/cookie/index.ts",
  "./accepts": "./src/helper/accepts/index.ts",
  "./compress": "./src/middleware/compress/index.ts",
  "./context-storage": "./src/middleware/context-storage/index.ts",
  "./cors": "./src/middleware/cors/index.ts",
  "./csrf": "./src/middleware/csrf/index.ts",
  "./etag": "./src/middleware/etag/index.ts",
  "./trailing-slash": "./src/middleware/trailing-slash/index.ts",
  "./html": "./src/helper/html/index.ts",
  "./css": "./src/helper/css/index.ts",
  "./jsx": "./src/jsx/index.ts",
  "./jsx/jsx-dev-runtime": "./src/jsx/jsx-dev-runtime.ts",
  "./jsx/jsx-runtime": "./src/jsx/jsx-runtime.ts",
  "./jsx/streaming": "./src/jsx/streaming.ts",
  "./jsx-renderer": "./src/middleware/jsx-renderer/index.ts",

Sources: jsr.json:8-36

Publish configuration within jsr.json explicitly includes source files, configuration manifests, and documentation while excluding test files jsr.json:107-110. Runtime test configurations like runtime-tests/deno/deno.json bind JSX runtime imports to local source files and configure standard library dependencies runtime-tests/deno/deno.json:1-13.

Sources: jsr.json:107-110, runtime-tests/deno/deno.json:1-13]

Bundle Size Auditing and Enforcement

To prevent performance regressions and maintain minimal footprints across core distribution files, Hono uses an automated bundle measurement harness driven by esbuild. The check script compiles the built entry point dist/index.js into an isolated temporary file using production settings, extracts exact byte and kilobyte measurements, and outputs structured benchmark JSON for validation pipelines.

async function main() {
  const tempDir = os.tmpdir()
  const tempFilePath = path.join(tempDir, 'bundle.tmp.js')
 
  try {
    await esbuild.build({
      entryPoints: ['dist/index.js'],
      bundle: true,
      minify: true,
      format: 'esm' as esbuild.Format,
      target: 'es2022',
      outfile: tempFilePath,
    })
 
    const bundleSize = fs.statSync(tempFilePath).size
    const metrics = []

Sources: perf-measures/bundle-check/scripts/check-bundle-size.ts:6-21

Configuration PropertyTarget ValuePurpose
entryPoints['dist/index.js']Specifies the compiled core bundle input file perf-measures/bundle-check/scripts/check-bundle-size.ts:12
bundletrueResolves and inlines all internal module dependencies perf-measures/bundle-check/scripts/check-bundle-size.ts:13
minifytrueStrips whitespace and mangles identifiers to measure production delivery size perf-measures/bundle-check/scripts/check-bundle-size.ts:14
format'esm'Enforces ECMAScript module output format perf-measures/bundle-check/scripts/check-bundle-size.ts:15
target'es2022'Sets the JavaScript language syntax target level perf-measures/bundle-check/scripts/check-bundle-size.ts:16
outfiletempFilePathWrites output to an OS temporary directory path perf-measures/bundle-check/scripts/check-bundle-size.ts:17

Sources: perf-measures/bundle-check/scripts/check-bundle-size.ts:11-18

Warning

The auditing harness guarantees cleanup by executing file deletion inside a finally block, ensuring temporary artifacts are wiped even if the compilation pass encounters errors perf-measures/bundle-check/scripts/check-bundle-size.ts:45-49.

Sources: perf-measures/bundle-check/scripts/check-bundle-size.ts:45-49]

Was this page helpful?