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

Option to place nested index.html entry point at the root of the output directory #19493

Closed
aweebit opened this issue Feb 22, 2025 · 5 comments
Closed

Comments

@aweebit
Copy link

aweebit commented Feb 22, 2025

{
  build: {
    outDir: 'dist/client',
    rollupOptions: {
      input: 'client/index.html',
    },
  },
}

This setup puts the index.html file into dist/client/client instead of dist/client so that in the output directory, the file's placement relative to the project's root is mimicked. Now, when running the dev server, index.html is only served at /client/, and not at / as I would expect.

By contrast, with the following setup, the bundled copy of the .js entry point is placed at the root of the output directory (dist/server) as expected:

{
  build: {
    ssr: true,
    outDir: 'dist/server',
    rollupOptions: {
      input: 'server/src/index.js',
    },
  },
}

Here is a small demonstration: https://stackblitz.com/edit/vite-index-html-in-subdir

An obvious solution to the problem is to set root: 'client', but why should that be necessary?

It all probably works as intended, but having at least an option to place index.html at the root of the output directory would be very nice.

Related: https://stackoverflow.com/a/72326219/9861000

@aweebit
Copy link
Author

aweebit commented Feb 27, 2025

@sapphi-red I could try to implement a solution and submit a PR if you tell me what your vision for the feature is. Should it be implemented as a build option like build.indexHtmlInRoot (or maybe build.hoistIndexHtml) so as not to be a breaking change?

Sorry about not using a template for this issue by the way, it was an accident.

@sapphi-red
Copy link
Member

We avoid adding options that are possible to achieve with other options. https://github.com/vitejs/vite/blob/main/CONTRIBUTING.md#think-before-adding-yet-another-option
If it has general upside of introducing it, we consider adding an option. But your current proposal sounds too specific to your case to add.

@aweebit
Copy link
Author

aweebit commented Feb 28, 2025

@sapphi-red is there any use in having the original location of index.html mimicked in the output directory? Do you think anyone relies on this behavior? Maybe it could be changed in the next major version release

@sapphi-red
Copy link
Member

I believe many people are doing so because it's the way written in the docs.
https://vite.dev/guide/build.html#multi-page-app

Introducing a breaking change also requires a reason. It may be useful for your case, but I'm not sure whether it is for others cases. If you organize the possible use cases and prove it is generally useful, then we can consider changing it. Without that, keeping the current behavior feels more beneficial to me.

@aweebit
Copy link
Author

aweebit commented Feb 28, 2025

@sapphi-red oh I see, supporting multiple entry points is actually a good reason to have this behavior, and differentiating between cases would make everything unnecessarily complicated. root: 'client' it is then! Thanks 😊

@aweebit aweebit closed this as completed Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants