Skip to content

Serve index.html inside subdirectory of public from subdirectory path #6714

@henribru

Description

@henribru

Clear and concise description of the problem

In some cases you might have an extra index.html that you want to serve at some nested path, without processing it through Vite. You can put it in a subdirectory of public, e.g. /public/foo/bar/index.html. However, if you do this, it will only be served at /foo/bar/index.html, and crucially not at /foo/bar/. This is different from the Webpack dev server, which will serve index.html files at the path of their containing directory, which caught me by surprise when migrating from Vue CLI to Vite.

https://stackblitz.com/edit/vitejs-vite-944tsu?file=public%2Ffoo%2Fbar%2Findex.html&terminal=dev

Suggested solution

If a subdirectory inside public contains an index.html, the index.html should be served at the path of that directory, either by default or as a configurable option.

Alternative

Instead of putting the directory in public, a possible workaround is to put it in the project root. If you do this it will serve the index file at the directory path. However, this means you need to manually copy the directory over to dist afterwards, which is a bit annoying since the whole point of having public is to automatically copy over files you don't want processed.

Edit: It's also a bit surprising to me that this behavior differs based on whether it's in public or the root

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Approved

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions