Skip to content

Allow package.json dependencies to be selectively transpiled / bundled #38

Open
@tjunnone

Description

The esbuild-node-externals plugin allows you to specify an allowList parameter for including dependencies into the bundle.

Why would you want this? For example:

  • A project (typically a monorepo) that uses internal dependencies of type "foo": "link:.src/some/path/foo" in the package.json. These aren't really external dependencies and they should be bundled/transpiled, they're just a convenient way to make bits of the source appear as top-level packages for import.
  • Creating single-file deployments, where the entire node_modules is intentionally bundled. It's possible and convenient if you have no native binary dependencies.
  • Bundling only selected (perhaps vendored) node_modules packages.

In our case, the first bullet prevents us from using esbuild-runner for some of our tools: our source tree is pure ESM, esr transpiles to CJS for running under node except the internally linked entries defined in packages.json aren't being bundled, so the result doesn't run.

I would like to suggest one or two options:

  • Add an esr config option allowList or externalsAllowList, specifying dependencies that should be transpiled/bundled.
  • Add an esr config option to disable the default externalizing of node_modules entirely. Then I could presumably add the esbuild-node-externals plugin myself to the config, or write my own plugin like in the esbuild docs, which supports fine-grained control of which dependencies to include or exclude.

If this is something you'd consider, I could try to make a PR.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions