Skip to content

(aws-lambda-nodejs): Support esbuild --inject #19133

@shishkin

Description

@shishkin

Description

esbuild has --inject argument that allows injecting code into final output. Current workaround is to use banner, but that mangles link breaks.

Use Case

This is useful to e.g. inject aws-sdk dynamic require import when using ESM output:

const AWS = await (async () => {
  const { createRequire } = (await import("node:module")).default;
  const require = createRequire(import.meta.url);
  return require("aws-sdk");
})();

Instead, currently requires a banner workaround:

      bundling: {
        format: OutputFormat.ESM,
        target: "esnext",
        banner: `const AWS=await (async ()=>{const { createRequire }=(await import("node:module")).default;const require=createRequire(import.meta.url);return require("aws-sdk");})();`,
      },

Proposed Solution

Support --inject natively in BundlingOptions.

Other information

No response

Acknowledge

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions