-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Bun plugin #16295
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 plugin #16295
Conversation
Modify integration tests Make `ChangedContent` possibly borrow its contents to avoid unnecessary allocations Revert "Make `ChangedContent` possibly borrow its contents to avoid unnecessary allocations" This reverts commit 10e2b0c. Did not result in significant performance gain. Modify workflow to test delete that for now make it work udpate update messed up lock file nice lol lmao sanity test blah asdf asdflkjasfd man wut wtf ??? cmon LOOOOOOOOOOOOOOOOOL clean tht bad boi up stuff bring it back bring it back change tests bye bye
Hey! Really excited for an official Bun plugin! We’re happy to collaborate and work on this together but to set the expectations right it will realistically take a few weeks before someone from our team can focus on this.
One reason for that is that we’re currently working on some changes that will break the existing Oxide <> Node APIs that are necessary fix some critical bugs. These changes will then impact the API design for the updated Oxide bindings necessary for the Bun plugin as well.
I’m sorry that we can’t hop onto this right away but we have to prioritize some other important fixes for the v4 release right now, I hope you understand. We’re pretty stoked about this feature though and hope to get to it soon!
9c60e4e
to
50cce50
Compare
Nanome203
commented
Apr 24, 2025
Any update on this?
marcospgp
commented
May 6, 2025
would love to see this make it through! using tailwind with bun is a much better experience than vite, yet the former is not even listed in the installation docs, and the latter is the default suggestion 😭
Nanome203
commented
Oct 13, 2025
bump
Uh oh!
There was an error while loading. Please reload this page.
This PR implements a Bun plugin that makes TailwindCSS fast in Bun.
c612d2faa37f2cff03c8620a08bb2def7268851bb183c2fa8e2763246b9243e5(bundling 2048 html + react + tailwind files)
Overview
This plugins is comprised of two parts:
Native bundler plugin
The native bundler plugin is used to scan the module graph in parallel with the
Scanner
struct from@tailwindcss/oxide
.The main logic for this code is in the
tw_on_before_parse
function.Native bundler plugins run in parallel on Bun's bundler threads and do not need to do UTF-16 <-> UTF-8 string conversions. This speeds up the plugin a lot.
Native bundler plugins are NAPI modules which export additional symbols (since NAPI modules themselves are dynamically loaded libraries which can be
dlopen()
'd). Thebun-native-plugin
crate handles the boilerplate for creating one.I placed the Bun plugin inside the existing
crates/node/lib.rs
(the@tailwindcss/oxide
package). This reduces the need to create more compiled artifacts at the cost of a relatively small binary size change:Please let me know if you would like me to split it out into its own separate package if you don't like the binary size change.
Sharing state between the native plugin and JS
The scanned candidates and other state are held inside a NAPI External. The struct in the code that does
this is called
TailwindContextExternal
.A NAPI External is a NAPI value which can be given to JS and which holds a
void*
data pointer. This data is inaccessible to JS, but a NAPI module can dereference the data and convert it to NAPI values.This looks a bit like this on the Rust side:
And the JS side:
napi-rs
version bumpThe
napi-rs
crate was updated to version2.16.15
so we can use theExternal::inner_from_raw()
function to turn anExternal
's*mut c_void
pointer back intoTailwindContextExternal
.JS plugin
The JS plugin
@tailwindcss-bun/src/index.ts
uses logic copied over from the vite plugin implementation but modified to work with Bun's plugin API.It invokes the native bundler plugin using the
.onBeforeParse
plugin API function:One thing to note is that Bun's bundler currently does not have an API that is analogous to
.addWatchedFile()
, so there is currently no way to add additional files to the module graph.Testing
I added a
integrations/bun/index.test.ts
file, please let me know if you would like more tests