Allow Vite entry points to be merged #53233
Merged
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.
This PR aims to solve an issue when Vite entry points are conditionally determined at runtime.
The existing
withEntryPoints
method in theVite
class replaces any entry points which have already been applied, and$this->entryPoints
is protected with no accessor method. So this backwards-compatible PR simply adds an additional method to merge a set of entry points with any which have already been set.I recently found myself in this situation:
app.css
andapp.js
.component-1.ts
,component-2.ts
etc.->viteTheme(['app.css', 'app.js'])
to set my entry points in their service provider.@vite(['component-2.ts'])
to include them as needed.However, if
component-2.ts
references assets which are also used byapp.css
(e.g. website logo etc.), duplicate chunk tags are rendered in the HTML markup.With this PR I can let Filament call
withEntryPoints
in its service provider, then later attach any additional components I need to include conditionally, before letting Filament render them once in a single output.There are other ways to solve this, I figured
mergeEntryPoints
was the simplest but am open to any other ideas.Let me know if any changes are necessary. Thanks! 🙏