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

fix: esbuild code split #403

Merged
merged 4 commits into from
Sep 15, 2021
Merged

fix: esbuild code split #403

merged 4 commits into from
Sep 15, 2021

Conversation

screetBloom
Copy link
Contributor

@screetBloom screetBloom commented Sep 8, 2021

Version

4.14.0

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Underlying tools
  • Other, please describe:

Questions

code splitting in esbuild must be esm. see here 👉 esbuild-splitting


When we encounter problems with __require.resolve we can solve them with esbuild --format=cjs

But in tsup we can't do that, we have to tsup --format cjs --no-splitting


I looked at the source code, and find:

  1. tsup defaults to cjs, tsup-src/index.js-355
  2. By default. --no-splitting will be undedined, So that always options.splitting !== false
  3. Then splitting && format === 'cjs' ? 'esm' : format will be esm

image


Related bugs


Steps to reproduce

tsup-mini-repo



This is also the first pr I mentioned to tsup. If can merged I will be very happy. And very much open to feedback on this PR if you have suggestions for improvements.

@vercel
Copy link

vercel bot commented Sep 8, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/egoist/tsup/21TqvuYBRPqrPeRSPdbz6iG8hvhQ
✅ Preview: https://tsup-git-fork-screetbloom-master-egoist.vercel.app

@screetBloom
Copy link
Contributor Author

@egoist
When have time you can check this pr, I would like to get some feedback💡

@egoist
Copy link
Owner

egoist commented Sep 15, 2021

When we encounter problems with __require.resolve we can solve them with esbuild --format=cjs

But in tsup we can't do that, we have to tsup --format cjs --no-splitting

This is expected in v4, we achieved code splitting for cjs by bundling the code in esm format and then convert to cjs format, see https://tsup.egoist.sh/#why-does-export--get-transpiled-to-module-exports-default

But it seems this has been causing a lot of issues, so I may disable code splitting for cjs format in v5. #317

@egoist egoist merged commit 49f48ea into egoist:master Sep 15, 2021
@github-actions
Copy link
Contributor

🎉 This PR is included in version 5.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants