-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Add Bun support #49241
Add Bun support #49241
Conversation
4d4c384
to
875ac39
Compare
ce5b63f
to
53353a1
Compare
Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
As per @rafaelfranca comment here, we may not need the release cut for each gem since this will not be released before the other gems. |
I loved this change <3 thanks @terracatta. Excited to see this live |
railties/lib/rails/generators/rails/app/templates/Dockerfile.tt
Outdated
Show resolved
Hide resolved
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
Amazing work! Just in time to our release |
Thanks for such a timely review! |
awesome stuff! 🖤 |
We need to get hotwired/turbo-rails#494 and https://github.com/hotwired/stimulus-rails merged (and all the assets gems re-released) if the next Rails beta is happening soon. |
def using_bun? | ||
# Cannot assume yarn.lock has been generated yet so we look for | ||
# a file known to be generated by the jsbundling-rails gem | ||
@using_bun ||= using_js_runtime? && Pathname(destination_root).join("bun.config.js").exist? |
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.
Memoization only helps here if this returns true
. Is there a big performance gain to memoizing @terracatta? If not we could remove it to simplify the code.
@terracatta hi, I tried I have a question.
I think yarn.lock is unnecessary for the default. How do you think about it? |
Agree. Mind to open a PR? |
see hotwired/stimulus-rails#125 |
Related PRs
This PR should only be merged when all of the following PRs have been merged and releases cut for each gem, otherwise the
--javascript bun
option will not work as expected.Also as a bonus I updated execJS so we can use the bun runtime for that as well.
Introduction
Bun is a new and viable alternative to the node.js runtime, yarn package manager, and esbuild bundler. Bun's primary differentiating characteristic is speed. It's often many multiple times faster than node.js and friends.
Since most vanilla Rails projects are looking to simply sprinkle a little JS here and there (but sometimes want a bit better more of the JS ecosystem than the import-maps provide) Bun is a really good fit and can be easily adopted by new rails projects.
Since it's such a nice fit, I propose we make it a first class citizen for folks looking to build a new Rails project with common defaults like stimulus, turbo, tailwind, etc. We should be able to spin up these projects with bun and not have to spend hours surgically removing remnants of Yarn/Node.
Example Bun and Tailwind Run
After this PR is merged, you will be able to spin up a new Rails project with options like
rails new --javascript bun --css tailwind --database sqlite3
and everything should "just work".Not once does the word "yarn" appear!
Dockerfile Support
This PR also updates the Dockerfile to support install/using the Bun runtime. Here is what it looks like to build it after the run above...