-
Notifications
You must be signed in to change notification settings - Fork 0
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
Bun build & pure ESM #157
base: master
Are you sure you want to change the base?
Bun build & pure ESM #157
Conversation
🦋 Changeset detectedLatest commit: 08dee35 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
await Bun.build({ | ||
entrypoints: ["src/index.ts"], | ||
outdir: "build", | ||
external: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tsup
automatically marks peer deps as external (see https://tsup.egoist.dev/#excluding-packages), Bun build does not. This is nicer since it's more explicit anyways
"main": "build/sigil.js", | ||
"module": "build/sigil.mjs", | ||
"types": "build/sigil.d.ts", | ||
"type": "module", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered adding "sideEffects": false
, but I don't think that works for our situation as we have e.g. CSS imports in main entry point. Note sideEffects
is boolean | string[]
; if passed an array of file paths it will mark them as files with side effects. We could do this, but I figured this was a better optimization for the future since the build system is/might be affected quite a bit, e.g. we might want to split the library into a single entry point per file in the future (further discussion and research to be had). In fact, we probably should set sideEffects
sooner than later, and that kind of refinement would be a good time to do it. https://linear.app/omnidev/issue/OMNI-245/set-sideeffects
Consequentially I decided to let downstream frameworks/bundlers handle the tree-shaking as we were doing before.
commit: |
eslint.config.mjs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry about reviewing this file, it was generated by the ESLint migration CLI and I only modified it to get it working. Since we are migrating to dprint/Biome later anyways, it's not a big deal, and the rules match what we had before (with the exception of import/no-cycle
disabled).
Description
Task link: https://linear.app/omnidev/issue/OMNI-172/migrate-from-tsup-to-bun-build-and-remove-cjs-support
tsup
to Bun build for bundling (tsup
still used for type declaration generation)The bundle should now be much smaller and build faster with the combination of general bundling optimizations (thanks to Bun) and dropping CJS artifacts.
Test Steps
If you have ideas on how to remove
tsup
, feel free to play around with it. Ideally, we'd use TypeScript isolated declarations, e.g. with thebun-plugin-dtsx
plugin ortsc
directly, but I didn't want to spend too much time on this and created https://linear.app/omnidev/issue/OMNI-242/use-isolated-declarations-for-type-output-and-remove-tsupEven if you get it working, I'd rather do that in a separate PR, that way we can publish this version as ESM only without completely changing the build structure and minimize the blast radius a bit.