-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Description
Currently only a subset of esbuild configs are exposed to users via BundlerOptions:
| export interface BundlingOptions { |
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:
| readonly buildArgs?: { [key:string] : string }; |
There are 2 alternatives for it:
- Expose additional options in
BundlingOptionslike{ esbuildConfigs: { [key: string]: string } }. This alternative may requires validating the duplicated options with other existing esbuild configs. - Expose a path option for users to provide custom
esbuild.jsfile, 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