Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: code splitting with commonjs #1341

Closed
DylanPiercey opened this issue Jun 2, 2021 · 1 comment
Closed

[Feature Request]: code splitting with commonjs #1341

DylanPiercey opened this issue Jun 2, 2021 · 1 comment

Comments

@DylanPiercey
Copy link

DylanPiercey commented Jun 2, 2021

I'm playing around with using esbuild for bundling library code with a setup like the following:

import { build } from "esbuild";

await build({
  external: [...], // Make node_modules external
  bundle: true,
  format: "esm",
  splitting: true,
  platform: "node",
  entryPoints: [
    "src/entry-a.ts",
    "src/entry-b.ts"
  ],
});

The problem is many libraries I work on require exposing multiple "entry point" files to the user. Think stuff like:

import a from "some-module/entry-a";
import b from "some-module/entry-b";

With the esm output it seems I can easily achieve this with the code splitting automatically deduping common code between the entries.

Currently though it's not possible to use format: "cjs" with splitting enabled. It would be great if this was possible because then it would allow me to use esbuild for these modules which require backward compat via providing cjs and esm builds.

If I run esbuild again on the output from the esm build with format: "cjs" it basically does what I want, however it re-inlines all of the runtime stuff again which isn't ideal.

@evanw
Copy link
Owner

evanw commented Jun 2, 2021

This happens because the code splitting feature is not finished yet. Closing as a duplicate of #16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants