Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently
Vite
helper is a singleton which mean that it may hold only one configuration at a time, allowing developer to customize only entry points and build directory per__invoke
call. This may cause problems in multi-app configurations.Example
In our project we use many SPAs within mainly legacy codebase. We manage our apps using Yarn workspaces. Axios, Echo and Ziggy configurations are shared between apps and stored in
resources/js/bootstrap.js
(resources/js/app.js
entry point), as suggested by Laravel. This bootstrap code is injected into main page layout and accessible throughout the entire project and all its sub-apps.The problem arose when it became necessary to debug specific app using
yarn dev
(vite
) command to serve its assets. Vite can't serve multiple applications at once, so we need to use separatehot
files for each application. But Laravel'sVite
helper can only hold one configuration... so here we are.Reasoning
Vite
helper to manage multiple app configurations;VITE_APP
environment variable.Backward compatibility
Vite
facade,Vite
helper injection and@vite
Blade directive should work as before, but instead of resolving singleton from application's container, they will point to "default" entry from theViteManager
.Vite
contract has been added to allowViteManager
to implement it.Configuration
There are 3 ways to configure Vite "apps":
config/vite.php
file (should probably be added intolaravel/laravel
repo?):boot
method:Usage
@viteApp
directive should be used in Blade templates to enjoy the power of multiappness to its fullest:Testing
I should probably add some tests for this feature, but I'm not good at it, so any help will be appreciated.
For now, I'll mark this PR as draft and try to write some tests.