[0.7.x] Provide hook to access dev url while transforming #195
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 exposes a hook that allows developers to transform code in serve mode (
npm run dev
) while giving access to the dev server URL. Transforming code in serve mode is already possible, however the developer does not have access to the dev server url.This is required for some plugins that assume absolute URLs starting with a
/
will be pointing at the vite dev server, e.g.should be interpreted as
Due to the nature of the Laravel integration, these URLs do not point to the Vite dev server; they point to the backend web server, such as Nginx.
There are a number of ways this could be addressed, but I decided on a low level implementation with the config hook to give maximum control so we don't make the wrong assumption with a generalisation.
The issue outlined in #194 and its linked issue is solved with the following configuration:
Resulting in the following output HTML
Alternative API
I did consider a "prefixWithDevServerUrl" config option, which does feel cleaner, but is more restrictive in its usage.
DIY example
It is possible to do this already with the existing tools on hand, but I do feel it is reasonable for us to include the proposed affordance.
fixes #194