laravel / vite-plugin

Laravel plugin for Vite.
MIT License
810 stars 152 forks source link

Base option not used in HMR url #288

Closed markieo1 closed 8 months ago

markieo1 commented 8 months ago

Vite Plugin Version

1.0.2

Laravel Version

10.42.0

Node Version

20.9.0

NPM Version

10.1.0

Operating System

Windows (WSL)

OS Version

1.2.5.0

Web browser and version

Google Chrome Version 122.0.6261.95 (Official Build) (64-bit)

Running in Sail?

No

Description

I have just upgraded from Vite 4 to 5. And have also upgraded the plugin. I have set the base option to: /frontend/. When we have a look at the hot file that is generated by the url we see the following url: https://vite-issue.test:5173. When we disable the Laravel Vite plugin, so just using the native implementation from Vite itself the following URL is generated (from: https://vite-issue.test:5173/frontend/@vite/client):

const socketHost = `${"vite-issue.test" || importMetaUrl.hostname}:${hmrPort || importMetaUrl.port}${"/frontend/"}`;

Seeing this, the Laravel Vite plugin should also take into account the base option. So that the url in the hot file is: https://vite-issue.test:5173/frontend/

The following config is used in this situation:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import fs from 'node:fs'

const host = 'vite-issue.test';

export default defineConfig({
    base: '/frontend/',
    plugins: [
        laravel({
            input: 'src/main.ts',
        }),
    ],
    server: {
        host,
        hmr: { host },
        https: {
            key: fs.readFileSync(`./vite-issue.test.key`),
            cert: fs.readFileSync(`./vite-issue.test.crt`),
        },
    },
});

Steps To Reproduce

driesvints commented 8 months ago

1.6.1

This version doesn't exists. Which one are you running?

markieo1 commented 8 months ago

1.6.1

This version doesn't exists. Which one are you running?

Sorry, it is the latest 1.0.2. I've changed the description.

timacdonald commented 8 months ago

Thanks for reporting this. We have a fix at #290. I will close this and we can monitor the PR.