or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

build.mdcode-quality.mddocumentation.mdindex.mdmonorepo.mdrelease.mdtesting.mdutilities.md
tile.json

build.mddocs/

Build System

Aegir's build system provides esbuild-based JavaScript/TypeScript compilation with browser bundle generation, TypeScript type declaration output, and bundle size analysis.

Capabilities

Build Command

Main build command that compiles TypeScript and generates browser bundles.

aegir build [options]

Options:
  --bundle         Build the JS standalone bundle (default: true)
  --bundlesize     Analyze bundle size (default: false)
  --bundlesizeMax  Max threshold for bundle size (string or object)
  --types          Build TypeScript declarations (default: true)

Build Configuration

Build behavior can be configured via .aegir.js or package.json:

interface BuildOptions {
  /** Build the JS standalone bundle */
  bundle: boolean;
  /** Analyze bundle size with threshold checking */
  bundlesize: boolean;
  /** Max bundle size thresholds */
  bundlesizeMax: string | Record<string, string>;
  /** Build TypeScript type declarations */
  types: boolean;
  /** esbuild configuration options */
  config: esbuild.BuildOptions;
}

Usage Examples:

// .aegir.js configuration
module.exports = {
  build: {
    bundle: true,
    bundlesize: true,
    bundlesizeMax: "100KB", // Single threshold
    // Or multiple thresholds:
    bundlesizeMax: {
      "dist/index.min.js": "50KB",
      "dist/worker.min.js": "80KB"
    },
    types: true,
    config: {
      // Custom esbuild options
      minify: true,
      sourcemap: true,
      target: 'es2020'
    }
  }
};

TypeScript Compilation

Automatic TypeScript detection and compilation when tsconfig.json is present.

# TypeScript compilation is automatically triggered when:
# 1. tsconfig.json exists in project root
# 2. --types option is true (default)
# 3. TypeScript files are detected in src/

The build process:

  1. Runs tsc for type declaration generation
  2. Uses esbuild for JavaScript bundling
  3. Generates source maps
  4. Performs bundle size analysis if enabled

Bundle Generation

Creates browser-compatible bundles with UMD wrapper for global usage.

// Default bundle configuration:
// - Input: src/index.js or dist/src/index.js (for TS)
// - Output: dist/index.min.js
// - Format: IIFE with UMD wrapper
// - Minification: enabled
// - Source maps: enabled
// - Global variable: PascalCase version of package name

Bundle Size Analysis

Analyzes and validates bundle sizes against configured thresholds.

// Bundle size analysis features:
// - Gzip size calculation
// - Threshold validation
// - Size comparison reporting
// - Generates dist/stats.json for esbuild analyzer
// - Fails build if size exceeds thresholds

Usage Examples:

# Build with bundle size analysis
aegir build --bundlesize

# Build with custom size threshold
aegir build --bundlesize --bundlesizeMax "50KB"

# Build types only (no bundle)
aegir build --no-bundle --types

Multi-Entry Builds

Support for multiple entry points and output files.

// Configure multiple entry points in .aegir.js:
module.exports = {
  build: {
    config: {
      entryPoints: {
        'index': 'src/index.js',
        'worker': 'src/worker.js'
      },
      outdir: 'dist'
    }
  }
};

// Results in:
// - dist/index.js
// - dist/worker.js

Build Output Structure

dist/
├── index.min.js      # Main browser bundle
├── index.min.js.map  # Source map
├── stats.json        # Bundle analysis (if --bundlesize)
└── src/              # TypeScript declarations (if --types)
    ├── index.d.ts
    └── types.d.ts

Environment Configuration

Build behavior adapts to project structure:

// JavaScript projects:
// - Entry point: src/index.js
// - Output: dist/index.min.js

// TypeScript projects (with tsconfig.json):
// - Compile TS to dist/src/ first
// - Entry point: dist/src/index.js
// - Output: dist/index.min.js + dist/src/*.d.ts

Error Handling

Build failures occur when:

  • TypeScript compilation errors
  • Bundle size exceeds configured thresholds
  • Missing source files
  • esbuild configuration errors
# Example error output:
# dist/index.min.js 150KB (▲50KB / 100KB)
# Error: Bundle size exceeds maximum threshold