ElMassimo / vite_ruby

⚡️ Vite.js in Ruby, bringing joy to your JavaScript experience
https://vite-ruby.netlify.app/
MIT License
1.32k stars 122 forks source link

Adds Bun support #392

Closed pftg closed 3 weeks ago

pftg commented 1 year ago

Description 📖

Adds support of Bun

Background 📜

Lately, Bun has adopted Vite, so we can use it for compilation assets.

vitalyliber commented 1 year ago

It will be great to see the Bun support!

pftg commented 1 year ago

@vitalyliber left to fix tests ;( but you can use my pr to confirm at least this "fast" workaround works for you too

pftg commented 1 year ago

@ElMassimo please review this PR

Notes:

This is a very naive approach to start using it. I already use it for my projects. Later, I saw some ideas to encapsulate all those package managers: remove duplication to find the current package manager.

pftg commented 1 year ago

I found some strange issue: (!) "base" option should start with a slash.

vladimirtemnikov commented 1 year ago

Hello, @pftg

Currently, bun does not support brotli: https://github.com/oven-sh/bun/issues/267

ViteRuby could work with bun, but we have vite-plugin-rails, which depends on brotli compression currently, may be we should wait some time before brotli will be implemented or conditionally enable brotli in plugin?

@ElMassimo any thoughts on this?

pftg commented 1 year ago

@vladimirtemnikov Yeah, you are right.

I had to disable brotli by the way, to use this version. So if this is a hard requirement to support the compress plugin, then there is a workaround.

So, for now, I use compress: { brotli: false } to use a bun. I'm ok with that ;)

I think better to start using without brotli to find more issues

pftg commented 1 year ago

@vladimirtemnikov @ElMassimo updated PR, what do you think to add notice in the Readme that it's not compatible with the vite rails plugin and list of supported bun versions?

pftg commented 1 year ago

Hmm, for development mode, everything was fine, but as soon as I tried to run on Heroku with production mode, the compilation got stuck. I found that when removing RubyPlugin, it's not stuck. I need help to set env to see the real problem. I'll try to look into it later.

Will be great to find a guide on how to set up development env for those plugins with bun and with integration testing in the real app.

dominikklein commented 8 months ago

Any ideas to bring this forward? Also rails 7.1. has now bun support. Would be nice to when it can also be used in the vite-ruby/rails context.

pftg commented 8 months ago

Yeah need to check latest tests, maybe now it's working. For now I'm using this approach to use bun https://jtway.co/integrating-bun-with-vite-ruby-for-lightning-fast-frontend-builds-bbd220fefdc0

pftg commented 8 months ago

@ElMassimo, with the latest bun, it looks like it works. I'm working on the cleanup in a separate PR https://github.com/jetthoughts/vite_ruby/pull/2

pftg commented 7 months ago

https://github.com/ElMassimo/vite_ruby/actions/runs/8186414098/job/22384757347?pr=392 - it's a new issue that appeared lately, I will check, but I believe I need to rebase

schonert commented 7 months ago

@pftg all green - great job!

adamburmister commented 4 months ago

Fantastic, just what I need, but I see this has sat around in a green state for a month+. Is there a plan to merge and publish this?

ElMassimo commented 3 months ago

Hi @pftg and other folks!

I've added support for a packageManager config option:

As part of that feature, it felt it was reasonable to add experimental support for bun, as it only required two lines of code.

Give it a try in vite_ruby-3.7.0.

The implementation in this pull request is reasonable, but I'd like to minimize the surface area of the library (users typically end up using internals even if they are marked as such).

pftg commented 3 months ago

@ElMassimo, could you clarify whether we should close this PR or if you need me to rework some parts?

pftg commented 3 months ago

Oh, it just adds settings to avoid auto-detection. In this pr, you find encapsulations of package managers at all, and I also added package manager settings too ;) https://github.com/ElMassimo/vite_ruby/pull/392/files#diff-756bec63bbf1c84f70817c5a763e016026db97b00b4b5e99a074dfc2ddb9521cR5

Shaglock commented 1 month ago

Hi @ElMassimo, are there any plans to merge this or make vite_ruby not depend on NodeJS being installed in the system?

pftg commented 3 weeks ago

@ElMassimo I forgot to mentione that there are missed more lines, you can check my PR what other changes need to add to make bun works. But I'd suggest to cleanup once and remove duplications with managing js packages, it was a little hard to find all those parts and cleanup it.

danielnc commented 3 weeks ago

@ElMassimo it would be nice to get this merged and how to enable bun with vite_rails we are using bun to compile assets in prod and works fine but dev still relies on node

ElMassimo commented 3 weeks ago

To clarify what I meant with:

I'd like to minimize the surface area of the library

I'm not interested in merging this refactoring, I'd prefer to keep the library lighter (less classes, smaller footprint).

Feel free to open an issue/PR if setting "packageManager": "bun" is not working as intended, providing error traces or relevant system information.


Given the misunderstanding after my reply, I've updated the CONTRIBUTING docs to minimize the chance of similar situations in the future.

A few notes from it: