winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.05k stars 196 forks source link

Custom bundling (esbuild) config #3410

Open skorfmann opened 1 year ago

skorfmann commented 1 year ago

Feature Spec

Wing now supports customizing the esbuild config for bundling inflight functions. This enables bundling functions with custom requirements, such as WebAsssembly modules or using custom esbuild plugins.

Use Cases

Implementation Notes

No response

Component

Compiler

Community Notes

github-actions[bot] commented 1 year ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

skorfmann commented 12 months ago

Just ran into the error described here https://answers.netlify.com/t/lambda-functions-fastify-error-cannot-find-module-string-decoder/40219/12 in one of the examples.

The solution outlined there

external_node_modules = ["readable-stream"]
skyrpex commented 12 months ago

A related use case is running cloud.Service during sim and accessing modules such as vite, where the default esbuild bundling config fails.

eladb commented 12 months ago
external_node_modules = ["readable-stream"]

@skorfmann would it make sense to always build with this setting when bundling for aws lambda?

skyrpex commented 11 months ago

Dependencies such as the fsevents dependency should also never be bundled AFAIK, but I'm not sure if by always excluding it we may hide a potential bundle problem.

skorfmann commented 8 months ago

This would help with using jsx in the Typescript SDK as well, e.g. something like this https://github.com/winglang/examples/pull/45

github-actions[bot] commented 5 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

Chriscbr commented 2 months ago

See also the bundling options offered by CDK here: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs.BundlingOptions.html

One design option could be to have some way to configure bundling on a per cloud.Function basis:

new cloud.Function(handler,
  env: {
    "KEY": "VALUE",
  },
  bundling: {
    external: ["fsevents"],
    minify: false,
  }
);

Another option is to have some way to configure bundling app-wide:

// inside the platform or in Wing, both can be supported
std.bundling.configure(
  external: @app.target == "aws" ? ["fsevents", "aws-sdk"] : ["fs-events"],
  minify: false,
);

When we expose an API for serializing an inflight into a string, bundling options would also be exposed for that naturally (this would be the lowest level).

@eladb thoughts?

eladb commented 2 months ago

Good idea - I think it might be sufficient as an initial step just support this at the app level.

Only thing, I'd try to avoid a global and expose it on via the @app:

@app.bundling.configure(...)