Skip to content

Extend config to support custom Vite styles and scripts - #4522

Merged
tabacitu merged 2 commits into
Laravel-Backpack:mainfrom
Kovah:v5-vite-assets
Aug 27, 2022
Merged

tabacitu merged 2 commits into
Laravel-Backpack:mainfrom
Kovah:v5-vite-assets

Conversation

@Kovah

@Kovah Kovah commented Jul 13, 2022

Copy link
Copy Markdown
Contributor

WHY

BEFORE - What was wrong? What was happening before this PR?

Assets built with the new Laravel Vite setup must be added by manually overriding the head.blade.php and scripts.blade.php files and adding the @vite() directive.

AFTER - What is happening after this PR?

Users are now able to add their assets built with Vite directly in the configuration side to side with the custom Mix styles and scripts.
Side note: Vite will be the go-to way to handle asset bundling in the future, as decided by the Laravel core team. So it makes sense to provide support for it in the near future.

HOW

How did you achieve that, in technical terms?

  • The config is extended with a vite_scripts and a vite_styles option. Both are simple arrays, currently there is no option to specify a custom manifest.json file for the Vite helper so it is left out.
  • The base/inc/head.blade.php view was extended with a block that adds the @vite() helper in the same way the current mix_styles are loaded.
  • The base/inc/scripts.blade.php view was extended with a block that adds the @vite() helper in the same way the current mix_styles are loaded.

Is it a breaking change?

I am not sure how backwards compatibility is handled in Backpack at the moment. The @vite() helper was addded in Laravel 9.19.
Adding a style or script to the config will output the directive itself without rendering, but users must upgrade to Laravel 9.19 anyway to be able to use Vite in the first place. Example with Laravel 9.10:
Bildschirmfoto 2022-07-13 um 18 59 44

Is there a suggested way to handle Blade template backwards compatibility?

How can we test the before & after?

This feature can be tested by setting up Vite asset bundling as described in the Laravel docs. After installing Backpack, add a custom stylesheet or script to the new config and load the admin dashboard.

@welcome

welcome Bot commented Jul 13, 2022

Copy link
Copy Markdown

BOOM! Your first PR with us, thank you so much! Someone will take a look at it shortly.

Please keep in mind that:

  • if this constitutes a breaking change, it might take quite a while for this to get merged; we try to emulate the Laravel release cycle as much as possible, so developers can upgrade both software once; this means a new big release every ~6 months;
  • even if it's a non-breaking change, it might take a few days/weeks for the PR to get merged; unless it's a no-brainer, we like to have some community feedback on new features, before we merge them; this leads to higher-quality code, in the end; we learnt this the hard way :-)
  • not all PRs get merged; sometimes we just have to hold out new features, to keep the packages lean; sometimes we don't include features that only apply to niche use cases;
  • we're not perfect; if you think we're wrong, call us out on it; but in a kind way :-) we all make mistakes, best we learn from them and build better software together;

Thank you!

--
Justin Case
The Backpack Robot

@pxpm

pxpm commented Aug 23, 2022

Copy link
Copy Markdown
Contributor

Hello @Kovah
Thank you very much for the contribution, sorry it took me so much time to come back here.

I agree with the proposed solution. I don't think there is much to do in regards to the needed Laravel version, I would just add a note on the config file with that information.

If @tabacitu agrees and you add the note, for me this is ready to merge.

Cheers

@tabacitu

Copy link
Copy Markdown
Member

Hat's off to you @Kovah . Flawless PR

slow_clap_cap

I wish all PRs we receive were like this. Including ours 😅
Thank you so much 🙏 Merging, will be released on Monday with a few more bug fixes and features.

@tabacitu
tabacitu merged commit 8d305ca into Laravel-Backpack:main Aug 27, 2022
@welcome

welcome Bot commented Aug 27, 2022

Copy link
Copy Markdown

WHOOP-WHOOP! Congrats, your first PR on this repo has officialy been merged.

party

You should also receive an email inviting you to the Community Members team. That's where we, commited community members, debate new features and decide what's in the Backpack roadmap. Feel free to ignore the invitation if you're not interested :-)

If you want to help out the community in other ways, you can:

  • give your opinion on other Github Issues & PRs;
  • chat with others in the Gitter Chatroom (usually for quick help: How do I do X);
  • answer Backpack questions on Stackoverflow; you get points, people get help; you can subscribe to the backpack-for-laravel tag by adding a new filter; that will send you emails when new questions come up with our tag;

Again. Thank you for the PR. You are a wonderful person. Keep 'em coming :-)
Cheers!

--
Justin Case
The Backpack Robot

P.S. Help in the Backpack community is rewarded with free Backpack commercial licenses. It's the least we can do. If you feel you've helped the community with PRs, help & other stuff, please apply for free licenses and mention this PR. You scratch my back, I scratch your back. Thank you!

@Kovah

Kovah commented Aug 27, 2022

Copy link
Copy Markdown
Contributor Author

Thanks for merging this! Looking forward to the release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants