npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@aligent/vite-plugin-handler

v0.3.1

Published

Vite plugin for bundling Lambda handlers

Readme

@aligent/vite-plugin-handler

Vite plugin that bundles Lambda handlers as individual ESM entry points using the Vite Environment API.

Each .ts file discovered under the given handler path gets its own build environment, producing a standalone dist/<entryName>/index.mjs output.

Installation

npm install --save-dev @aligent/vite-plugin-handler

Requires vite >= 8.0.14 as a peer dependency.

Usage

// vite.config.mjs
import { defineConfig } from 'vite';
import { handlerBundle } from '@aligent/vite-plugin-handler';

export default defineConfig({
    plugins: [handlerBundle('src/runtime/handlers')],
});

Options

handlerBundle(handlersPath, options?) accepts an optional second argument:

| Option | Type | Default | Description | |---|---|---|---| | concurrency | number | Infinity | Max concurrent environment builds. Useful for resource-constrained CI. | | shims | boolean \| ConditionalShim[] | true | Controls conditional shims. true uses the built-in shims, false disables all shims, or pass a ConditionalShim[] to replace the built-ins with your own. | | external | (string \| RegExp)[] | [] | Additional modules to exclude from the bundle, appended to Node.js built-ins. | | moduleTypes | Record<string, string> | {} | Extra Rolldown module type overrides (e.g. { '.graphql': 'text' }). |

handlerBundle('src/runtime/handlers', {
    concurrency: 2,
    shims: false,
    external: ['@aws-sdk/client-s3', /^@smithy\//],
    moduleTypes: { '.graphql': 'text' },
});

Custom shims

Pass a ConditionalShim[] to replace the built-in shims with your own. Each shim is only injected when its needles are found in the rendered chunk:

import { handlerBundle } from '@aligent/vite-plugin-handler';
import type { ConditionalShim } from '@aligent/vite-plugin-handler';

handlerBundle('src/runtime/handlers', {
    shims: [
        {
            needles: ['myGlobal'],
            statement: 'const myGlobal = {};',
        },
    ],
});

Behaviour

  • Automatically skips handler environment creation when running under vitest (VITEST=true), so tests run without interference.

  • Strips built-in Vite plugins that don't apply to Node.js bundling:

    | Plugin | Why removed | |---|---| | vite:watch-package-data | Watches package.json for HMR — no HMR in builds | | vite:modulepreload-polyfill | Browser <link rel=modulepreload> — no browser | | vite:html-inline-proxy | Inline scripts in HTML — no HTML | | vite:css | CSS parsing/transforms — no CSS | | vite:css-post | CSS post-processing — no CSS | | vite:css-analysis | CSS dependency analysis — no CSS | | vite:wasm-helper | WASM loading for browsers | | vite:worker | Web Workers — no browser | | vite:worker-import-meta-url | Web Worker URL resolution — no browser | | vite:asset | Static asset handling (images, fonts) — no static assets | | vite:asset-import-meta-url | new URL('asset', import.meta.url) for assets | | vite:build-html | HTML entry processing — no HTML | | vite:client-inject | HMR client injection — no HMR | | vite:forward-console | Forwards console to Vite overlay — dev server only | | vite:terser | Terser minifier — minification is disabled | | vite:ssr-manifest | SSR manifest generation — not doing SSR |

  • Conditionally injects shims via renderChunk only when the bundled output actually references the corresponding identifiers:

    | Shim | Trigger | Purpose | |---|---|---| | __dirname / __filename | __dirname or __filename in chunk | ESM equivalents for bundled CJS dependencies | | node:http2 | node_http2 in chunk | Works around a rolldown bug that drops externalised builtin imports |

  • Minification is always disabled. Lambda handler bundles prioritise debuggability (readable stack traces, easier CloudWatch inspection) over bundle size.

  • Sourcemaps are controlled by NODE_ENV rather than Vite's --mode flag — they are enabled unless NODE_ENV=production. This uses the deploy-time environment as the signal because Lambda builds always invoke vite build regardless of target stage.

  • Shim injection in renderChunk uses MagicString to produce proper sourcemaps, so prepended shim code does not shift source positions in downstream tooling.

  • Externalises all Node.js built-in modules.

  • Externalises .node native addon files. Compiled C/C++ addons cannot be bundled into JavaScript, so they are automatically excluded. Common packages with native addons include cpu-features (used by ssh2), sharp, bcrypt, better-sqlite3, and @parcel/watcher.

  • Outputs ESM format with index.mjs entry file names.

Development

# Build
npx nx build vite-plugin-handler

# Test
npx nx test vite-plugin-handler