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

@nikovirtala/projen-bundle-lambda-function-code

v0.0.103

Published

A Projen component for automatically bundling AWS Lambda function code using esbuild.

Readme

@nikovirtala/projen-bundle-lambda-function-code

A Projen component for automatically bundling AWS Lambda function code using esbuild.

Features

  • Auto-discovery: Automatically finds Lambda handler files with configurable extensions
  • ESBuild bundling: Uses esbuild for fast, efficient bundling
  • CDK integration: Generates CDK constructs with pre-bundled Lambda code
  • TypeScript support: Full TypeScript support with configurable tsconfig
  • Flexible configuration: Customizable bundling options per function

Installation

npm install @nikovirtala/projen-bundle-lambda-function-code

Usage

Basic Setup

Add the bundler to your Projen TypeScript project:

import { LambdaFunctionCodeBundler, Bundler } from '@nikovirtala/projen-bundle-lambda-function-code';

const project = new typescript.TypeScriptProject({
  // ... your project config
});

// Add the bundler component
new Bundler(project);

// Auto-discover and bundle Lambda functions
new LambdaFunctionCodeBundler(project, {
  extension: '.lambda.ts',
  srcdir: 'src',
});

Lambda Handler Files

Create Lambda handler files with the configured extension:

// src/hello-world.lambda.ts
export const handler = async (event: any) => {
  return {
    statusCode: 200,
    body: JSON.stringify({ message: 'Hello World!' }),
  };
};

Generated CDK Constructs

The bundler automatically generates CDK constructs for each Lambda function:

// Generated: src/hello-world-code.ts
import * as path from 'path';
import { aws_lambda } from 'aws-cdk-lib';

export const HelloWorldFunctionCode = aws_lambda.Code.fromAsset(
  path.join(__dirname, '../assets/hello-world'),
);

Use in your CDK stack:

import { HelloWorldFunctionCode } from './hello-world-code';

new aws_lambda.Function(this, 'HelloWorldFunction', {
  runtime: aws_lambda.Runtime.NODEJS_20_X,
  handler: 'index.handler',
  code: HelloWorldFunctionCode,
});

API Reference

Bundler

Main component for esbuild bundling support.

new Bundler(project, {
  esbuildVersion?: string;     // esbuild version requirement
  assetsDir?: string;          // output directory (default: "assets")
  addToPreCompile?: boolean;   // add to pre-compile phase (default: true)
  loaders?: Record<string, string>; // file extension loaders
});

LambdaFunctionCodeBundler

Auto-discovers and bundles Lambda functions.

new LambdaFunctionCodeBundler(project, {
  extension: string;           // file extension to discover (e.g., ".lambda.ts")
  srcdir: string;             // source directory to scan
  bundleOptions?: {           // default bundling options
    externals?: string[];
    sourcemap?: boolean;
    target?: string;
    platform?: string;
    // ... more options
  };
});

LambdaFunctionCodeBundle

Bundle individual Lambda functions.

new LambdaFunctionCodeBundle(project, {
  entrypoint: string;         // path to Lambda handler file
  extension: string;          // file extension
  constructFile?: string;     // generated construct file name
  constructName?: string;     // generated construct class name
  bundlingOptions?: BundlingOptions;
});

Bundling Options

Customize esbuild behavior:

interface BundlingOptions {
  externals?: string[];       // external dependencies to exclude
  sourcemap?: boolean;        // include source maps (default: true)
  target?: string;           // esbuild target (default: "esnext")
  platform?: string;        // target platform (default: "node")
  outfile?: string;          // output filename (default: "index.mjs")
  format?: string;           // output format (esm, cjs, iife)
  minify?: boolean;          // minify output (default: true)
  tsconfigPath?: string;     // TypeScript config path
  loaders?: Record<string, string>; // file loaders
}

Examples

Custom Bundling Options

new LambdaFunctionCodeBundler(project, {
  extension: '.lambda.ts',
  srcdir: 'src/functions',
  bundleOptions: {
    externals: ['aws-sdk'],
    minify: false,
    sourcemap: true,
    target: 'node18',
  },
});

Individual Function Bundle

new LambdaFunctionCodeBundle(project, {
  entrypoint: 'src/special-function.lambda.ts',
  extension: '.lambda.ts',
  constructName: 'SpecialFunction',
  bundlingOptions: {
    externals: ['@aws-sdk/client-s3'],
    format: 'cjs',
  },
});

Development

This project uses Projen for configuration management.

# Install dependencies
pnpm install

# Build the project
pnpm build

# Run tests
pnpm test

# Update project configuration
npx projen

License

MIT