laravel / horizon

Dashboard and code-driven configuration for Laravel queues.
https://laravel.com/docs/horizon
MIT License
3.87k stars 658 forks source link

Simplify asset story #1438

Closed timacdonald closed 6 months ago

timacdonald commented 6 months ago

Horizon was migrated to Vite + laravel-vite-plugin. The laravel-vite-plugin is not meant for packages. There was some additional work done to support the asset URL. We ended up having a lot of workarounds to make things work.

This PR rethinks Horizon's asset story completely to try and simplify things.

Main changes

Inline assets on the dashboard

CSS, JS, and the favicon are now delivered inline. The horizon dashboard is a single-page app, so there is no real-world drawbacks here IMO.

The total transfer size is ~280kb over the wire. Yes we lose browser caching of the assets, but we also had to introduce a lot of manual work to add cache busting and 280kb is nothing.

This just works™️, assets are always up to date, we no longer have to publish assets whenever we change them, and applications that use a CDN for assets are no longer having to deliver assets via their web servers - which was an issue that has been raised.

Remove laravel-vite-plugin and usages of the Vite facade.

As I mentioned, the laravel-vite-plugin is meant for Laravel apps. It doesn't really offer anything for packages and in some ways makes things harder.

We just use raw Vite now when working on Horizon.

# Build for production
npm run build

# Rebuild on changes
npm run watch

Minor changes

Considerations

github-actions[bot] commented 6 months ago

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

timacdonald commented 6 months ago

@driesvints, if you have a release script for this you will need to update the build command to npm run build.

driesvints commented 6 months ago

@timacdonald our repos with asset compilation use the compile assets workflow. I've made the necessary adjustments but just FYI it's this: https://github.com/laravel/horizon/commit/8d31ff178bf5493efc2b2629c10612054f31f584

timacdonald commented 6 months ago

Thanks!