CDK Bundler
cdkx is a specialized command-line interface (CLI) tool designed to bundle assets for AWS Cloud Development Kit (CDK) applications. Primarily utilizing `esbuild` for its high performance, it streamlines the process of preparing CDK-managed code and assets for deployment. The current stable version is 1.0.12. This package aims to provide an efficient bundling solution for TypeScript-based AWS CDK projects, making it easier to manage dependencies and optimize deployment artifacts. Its key differentiator lies in its focused approach to integrating `esbuild` directly into the CDK development workflow, offering a simpler alternative for asset bundling compared to configuring `esbuild` manually or relying on broader build tools. While not an official AWS CDK tool, it integrates with `@aws-cdk/core` to provide a tailored bundling experience for CDK constructs.
Common errors
-
Error: This package is private and cannot be published. (code EPRIVATE)
cause Attempting to `npm publish` a package with `"private": true` in its `package.json`.fixBefore publishing, set `"private": false` in `package.json`. Remember to revert it if `cdkx` is part of a monorepo that requires it to be private during local development. -
Cannot find module 'esbuild'
cause The `esbuild` dependency is not correctly installed, or the Node.js environment cannot locate it.fixEnsure `esbuild` is listed in your project's `dependencies` and run `npm install` or `yarn install`.
Warnings
- gotcha When publishing your package, ensure `private` is set to `false` in `package.json`. If `cdkx` is part of a larger `lerna` monorepo where it's typically marked `private` during development, this step is critical before running `npm publish`.
- gotcha The `cdkx` tool wraps `esbuild`. For advanced `esbuild` configurations not directly exposed by `cdkx` options, you might need to use `esbuild` directly or contribute features to `cdkx`.
Install
-
npm install cdkx -
yarn add cdkx -
pnpm add cdkx
Imports
- cdkx
import { cdkx } from 'cdkx'npx cdkx bundle [options]
- bundle
cdkx bundle src/my-lambda.ts --out-dir dist
- Node.js API (hypothetical)
import { bundleAsset } from 'cdkx'; // Usage example (API might not be officially exposed or documented for direct use)
Quickstart
npx cdkx bundle src/lambda/my-function.ts \
--platform=node \
--target=es2020 \
--format=cjs \
--sourcemap \
--bundle \
--out-dir=./cdk.out/assets \
--external:aws-sdk
console.log("CDK asset bundled successfully to cdk.out/assets");
// In a CDK stack:
// import * as lambda from 'aws-cdk-lib/aws-lambda';
// import * as path from 'path';
// new lambda.Function(this, 'MyLambdaFunction', {
// runtime: lambda.Runtime.NODEJS_18_X,
// handler: 'my-function.handler',
// code: lambda.Code.fromAsset(path.join(__dirname, '../../cdk.out/assets'))
// });