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

Provide path option and apply transform for index.html #528

Closed
jakobrosenberg opened this issue Jul 8, 2020 · 3 comments · Fixed by #793
Closed

Provide path option and apply transform for index.html #528

jakobrosenberg opened this issue Jul 8, 2020 · 3 comments · Fixed by #793
Labels
enhancement New feature or request feat: html

Comments

@jakobrosenberg
Copy link

Is your feature request related to a problem? Please describe.
I'm trying to integrate Vite into a framework. The rigid index.html unfortunately makes this impossible.

The framework itself needs to transform index.html while 3rd part integrations require hacks to work with index.html in the project root.

Describe the solution you'd like
Providing a path option for index.html and apply transforms during build.

Describe alternatives you've considered
I tried centering the framework around Vite's index.html convention, but had to give up as it broke compatibility with other integrations.

Additional context
Hardcoding file structures when there's no technical requirement should always be avoided IMO. Good practices may be intended, but any value is lost when the price is incompatibility and ugly hacks.

@yyx990803 yyx990803 added the enhancement New feature or request label Jul 15, 2020
@yyx990803
Copy link
Member

yyx990803 commented Jul 15, 2020

You can actually use a custom server plugin to serve whatever HTML you want:

createServer({
  configureServer: ({ app }) => app.use(async (ctx, next) => {
    // wait for vite history fallback
    // this redirects all valid paths to `index.html`
    await next()
    if (ctx.url.endsWith('.html')) {
      ctx.body = ... // serve whatever html you want or transform ctx.body (if exists)
      ctx.status = 200
    }
  })
})

@jakobrosenberg
Copy link
Author

Thanks for the suggestion @yyx990803. I got it working for development, but build is another story. Not sure how to tackle that.

https://github.com/vitejs/vite/blob/master/src/node/build/index.ts#L268

@shadow-light
Copy link

Another related thing that would be really nice is to be able to have index.pug (or other language) transformed to index.html, so that all the HTML in a project could be written in pug/etc rather than only components.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feat: html
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants