question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-lambda-nodejs): support additional esbuild configurations(main-fields)

See original GitHub issue

Description

Currently only a subset of esbuild configs are exposed to users via BundlerOptions:https://github.com/aws/aws-cdk/blob/29039e8bd13a4fdb7f84254038b3331c179273fd/packages/%40aws-cdk/aws-lambda-nodejs/lib/types.ts#L6

However there are much more configs supported by esbuild: https://esbuild.github.io/api/

A good example is main-fields: by default esbuild will prefer main entry of package.json for Node.js app. However, this is usually the entry point for CommonJS module, thus, esbuild cannot treeshake it well. If we specify the esbuild to prefer the module entry point, the function bundle can be reduced more with tree shaking.

Use Case

If main-fields is specified for AWS SDK v3, the SDK size can be further reduced by more than 50% with tree shake enabled.

Proposed Solution

Even though this request is asking main-fields config explicitly, CDK can also expose interface for arbitrary esbuild config. Just like buildArgs for the image building step: https://github.com/aws/aws-cdk/blob/29039e8bd13a4fdb7f84254038b3331c179273fd/packages/%40aws-cdk/aws-lambda-nodejs/lib/types.ts#L210

There are 2 alternatives for it:

  1. Expose additional options in BundlingOptions like { esbuildConfigs: { [key: string]: string } }. This alternative may requires validating the duplicated options with other existing esbuild configs.
  2. Expose a path option for users to provide custom esbuild.js file, which calls the esbuild JS API. This will ignore all other esbuild configs. The advantage is that it supports all the future esbuild configs.

Other information

No response

Acknowledge

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alexbaileyukcommented, Mar 10, 2022

Updated the PR and left my thoughts on the comment in question.

Fantastic. I see it has been merged as well which is great. Thanks for the quick turn around!

1reaction
ryparkercommented, Mar 4, 2022

Thanks for the ping. I’ll give this a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building Node.js Lambda functions with esbuild
The esbuild bundler supports Lambda functions that you write in TypeScript. To build a Node.js Lambda function with esbuild, add a Metadata object...
Read more >
Building Node.js Lambda functions with esbuild
The esbuild bundler supports Lambda functions that you write in TypeScript. To build a Node.js Lambda function with esbuild, add a Metadata object...
Read more >
Package your NodeJS Lambda functions individually with ...
Learn about packaging your NodeJS-based AWS Lambda functions with esbuild for improved cold start times and reduced deployment package size.
Read more >
awslambdanodejs
This library provides constructs for Node.js Lambda functions. Node.js Function. The NodejsFunction construct creates a Lambda function with automatic ...
Read more >
@aws-cdk/aws-lambda-nodejs | Yarn - Package Manager
Amazon Lambda Node.js Library. cdk-constructs: Stable. This library provides constructs for Node.js Lambda functions. Node.js Function.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found