Skip to content

Base option not used in HMR url #288

Closed
@markieo1

Description

@markieo1

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

  • Ensure there's a key and cert file available for your site.
  • Configure Vite as specified.
  • Start Vite: npm run dev
  • The generated url in the hotfile is https://vite-issue.test:5173. Instead of https://vite-issue.test:5173/frontend/.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions