Use bun for all front end concerns#2015
Conversation
The central config file ensures both Bun and Lucky use the same output dir, manifest file, source dirs, etc.
The bake script handles all front-end asset needs. It builds and moves assets and generates a manifest. In development, it runs a watcher, starts a WebSocket-server, and creates unminified builds. In production it minifies and fingerprints all assets.
This test suite uses Bun's built in test helpers.
Also renames the original generate_asset_helper to match Bun's variant.
By default it now uses Bun. with the `legacy` flag, the old Mix manifest can be generated. The `css_entry_points` class method is used for the HMR script to dynamically reload CSS files without a full page reload. This commit also removes duplication in the dynamic_asset helpers.
This adds a development tag helper rendering a reload script that connects with Bun's WebSocket server. It performs hot reloads for changes to CSS files and full page reloads for any other assets.
Check if a source file exists and avoid processing if it does not, and log a warning reference.
Rather than writing Bun's manifest file to the assets dir, write it to the public dir as bun-manifest.json.
|
This is so awesome! And I love that you added some tests for the javascript stuff too. That'll be a huge help in maintaining it. Thanks for putting this all together. I feel like this pushes Lucky into some more much needed modern setup 🙌 As for the asset build system...
These were part of what I was talking about possibly reverting. This was added in order to make the asset system pluggable. I'm still not sure if I should revert them or not. The idea would be that you configure whichever build system you wanted to use, and then Lucky internally knows when to call the different commands it needs for each... However, I don't think it was ever completed because we got stuck on just trying to make Vite work out of the box. On the one hand, it's basically useless code sitting around doing nothing so probably should be removed... On the other hand, we could actually just use it and then maybe the asset builder wouldn't need weird args like |
|
Thanks! Bun feels really snappy and I love that it doesn't require any dependencies. Not even for the test suite. A pluggable asset system is a great idea in itself I think, and adding the Bun counterparts wouldn't be a lot of work. But I'm not completely clear when it would be invoked. Would that be at compile time like the current The only thing is that if it's kept around, the Vite implementation should be equally usable as the Mix and Bun versions. We could harvest the good parts from the LuckyVite shard which works, but is it worth the effort? It's not that any of us has the spare time to put in the effort into something that may not even be used at all 😄. UPDATE:
And then the frontend would require a bit of manual configuration which is inevitable I think. |
My two cents on this. For now I think it may be better to park it. It's only once every five years you'd need to reconsider the asset build system, and I suppose you don't want to add support for every bundler available. Lucky has always been opinionated (PostgreSQL, LuckyHTML, Laravel Mix, etc.) and personally I don't feel that should change for the bundler. It would be good to restructure the asset manifest builder a bit so that it's easier to add different manifest parsers, and switch between the build systems with a single argument on the |
|
Is there something I can still do for the Bun implementation? Like reworking the asset manifest builder to make it switch between Mix/Vite/Bun? Or if you need more time to think about it, that's fine with me. I don't want to rush you. This weekend I'll be mostly working on the |
|
I like your suggestion of changing the I see the title still has Thanks again for all this work. This is huge! 🙌 |
|
Great, then I'll restructure the asset manifest builder as well to work with all bundlers. And yes, this is still a WIP. Hopefully by the end of this weekend it will be ready for a first review round. I'll remove the WIP from the title and let you know when it's ready. |
|
@jwoertink I've reworked the asset manifest builder to handle all three bundlers and changed the signature on the The Bun implementation still works as expected, I've tested it locally with the Fluck website. The Mix and Vite implementations are harder to test because of the pluggable asset system. So I suppose that should be rolled back first to evaluate the situation. I also don't have any Lucky apps still using mix, so it's difficult to test a real-world app from my side. UPDATE |
jwoertink
left a comment
There was a problem hiding this comment.
I'm not seeing anything glaring in any of this. I think it's all looking good. Super stoked to get this in, and that's way awesome you got such a nice performance boost. I have some mix and vite apps I can test this all against.
I'll get this merged in, and then work on ripping out that other stuff and make sure the CLI is all prepped. Thanks!!
|
Fantastic! Let me know if you need any help with the CLI. You can always look here for setup pointers: https://codeberg.org/fluck/website. Although that repo has the code still embedded. |
Changes
This is just the current state of the Bun implementation as a first draft. This works locally in development in the Fluck website app, and all tests pass as expected.
Changes needed in the Lucky app itself are:
Procfile.dev
package.json
src/components/shared/layout_head.cr
Other
bun run prodfor deploymentconfig/bun.jsonfile (optional, all fallbacks are in place)Questions
I'd like to add more tests but I'm a bit stuck. More specifically I'm a bit confused by the
Lucky::AssetBuilder::MixandLucky::AssetBuilder::Viteclasses. They only ever seem to be used in the test suite. What's their purpose? Are these preparations for the pluggable asset system?What confuses me is that they are part of
srcbut only used inspec. Of course I can add aBunvariant with a test suite, but I thought I'd ask first.