Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append base to hot file #290

Merged
merged 1 commit into from
May 9, 2024
Merged

Append base to hot file #290

merged 1 commit into from
May 9, 2024

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Mar 18, 2024

fixes #288

Fixes an issue where the base path is not included in the /public/hot file. This issue only impacts the npm run dev command. When building, assets are appended with the configured base.

base description

Screenshot 2024-03-18 at 13 04 32

What

If we were to set the base path to /frontend/:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    base: '/frontend/',
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
    ],
});

Then the dev server will be appended with /frontend/:

Screenshot 2024-03-18 at 13 08 15

However, the hot file we write will not contain the /frontend base path:

Screenshot 2024-03-18 at 13 08 43

So we do not create the correct URLs in Laravel. With this change in place, the hot file now contains the correct base.

Screenshot 2024-03-18 at 13 12 26

Implementation notes

Vite normalizes the base value before we get access to it. The following table shows how Vite normalizes different values and what we end up appending to the hot file.

The only valid values for this option are undefined, an empty string, ./, or an absolute URL, i.e., https://example.com/... or /...

User config Normalized Hot file
undefined "/" ""
"" "/" ""
"/" "/" ""
"./" "/" ""
"/frontend" "/frontend/" "/frontend"
"/frontend/" "/frontend/" "/frontend"
"https://example.com" "/" ""
"https://example.com/" "/" ""
"https://example.com/frontend" "/frontend/" "/frontend"
"https://example.com/frontend/" "/frontend/" "/frontend"

Copy link

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 timacdonald marked this pull request as ready for review March 18, 2024 02:27
@timacdonald timacdonald requested a review from jessarcher March 18, 2024 02:27
@timacdonald
Copy link
Member Author

Context: In Vite 4, the dev server works with and without the /frontend prefix. In Vite 5 is breaks.

Screenshot 2024-03-18 at 13 41 25

@jessarcher
Copy link
Member

Looks like this might also help with #197, as it's a similar implementation to #207.

@taylorotwell taylorotwell merged commit fcd76b5 into laravel:1.x May 9, 2024
3 checks passed
@timacdonald timacdonald deleted the base branch May 10, 2024 05:31
@gazben
Copy link

gazben commented May 16, 2024

@driesvints Can you make new release with this fix please?

@driesvints
Copy link
Member

@gazben done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Base option not used in HMR url
5 participants