Skip to content

Add size-limit for small libraries with GitHub Actions #297

Description

@yamcodes

📋 Summary

Add size-limit to track and enforce bundle size limits for the arkenv package. This will help prevent bundle size regressions and maintain the library's small footprint.

📊 Current Bundle Sizes

Based on gzipped sizes of the current build:

  • ESM (dist/index.js): 2,015 bytes (1.97 KB)
  • CJS (dist/index.cjs): 2,446 bytes (2.39 KB)

🎯 Proposed Limits

Set limits to current size + 1KB:

  • ESM (dist/index.js): 3,039 bytes (≈ 3.0 KB)
  • CJS (dist/index.cjs): 3,470 bytes (≈ 3.4 KB)

🔧 Implementation Steps

1. Install Dependencies

Add size-limit and the preset for small libraries:

pnpm add -D size-limit @size-limit/preset-small-lib --filter=arkenv

2. Configure size-limit

Add size-limit configuration to packages/arkenv/package.json:

{
  "size-limit": [
    {
      "path": "dist/index.js",
      "limit": "3.0 KB"
    },
    {
      "path": "dist/index.cjs",
      "limit": "3.4 KB"
    }
  ]
}

3. Add size Script

Add the size script to packages/arkenv/package.json:

{
  "scripts": {
    "size": "size-limit"
  }
}

4. Create GitHub Actions Workflow

Create .github/workflows/size-limit.yml:

name: size-limit

on:
  pull_request:
    branches: [main]

jobs:
  size:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: pnpm/action-setup@v4
      - uses: actions/setup-node@v6
        with:
          node-version: lts/*
          cache: pnpm
      - run: pnpm install
      - run: pnpm run build --filter=arkenv
      - uses: andresz1/size-limit-action@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          skip_step: build
          build_script: build
          package_manager: pnpm
          directory: packages/arkenv

5. Update Test Suite (Optional)

Consider adding size check to the test suite:

{
  "scripts": {
    "test": "vitest && pnpm run size"
  }
}

📚 References

✅ Acceptance Criteria

  • size-limit installed and configured
  • Size limits set to current size + 1KB for both ESM and CJS builds
  • GitHub Actions workflow created and working
  • Size check runs on pull requests
  • Size limit comments appear on PRs when limits are exceeded
  • Documentation updated (if needed)

🎨 Additional Notes

  • The preset @size-limit/preset-small-lib uses esbuild and file plugins, which is perfect for small libraries
  • Size-limit will use Brotli compression by default (which matches our current gzipped measurements)
  • The GitHub Action will automatically comment on PRs with size information and reject if limits are exceeded

Metadata

Metadata

Assignees

No one assigned

    Labels

    @arkenv/vite-pluginIssues or Pull Requests involving the Vite plugin for ArkEnvarkenvChanges to the `arkenv` npm package.github actionsPull requests that update GitHub Actions codeinfraInfrastructure related issue or pull request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions