`transformIndexHtml` hook gets the wrong html filepath when running Multi-Page
See original GitHub issueDescribe the bug
transformIndexHtml
hook gets the wrong html filepath when running Multi-Page.
Reproduction
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolvePath } from './utils'
export default defineConfig({
plugins: [
vue(),
],
build: {
rollupOptions: {
input: {
main: resolvePath('index.html'),
landingPage: resolvePath('landing-page/index.html'),
},
},
},
})
Project root directory structure:
- index.html
- landing-page
- index.html
in the transformIndexHtml
hook:
async transformIndexHtml(html, { filename }) { ... }
Go to /landing-page/
filename
will be <root>/landing-page/index.html
witch is correct.
but, if go to /landing-page/foo/
filename
will be <root>/index.html
which is the the wrong filename.
it really should be <root>/landing-page/index.html
when the url is subpath of /landing-page/
.
Sure I can fix this by add an additional middleware to the ViteDevServer, but it really should detect if it is a Multi-Page, if it is, add the routes for it automatically.
Reproduction
- clone https://github.com/ssr-glue/vite-plugin
- run
yarn
- remove comment https://github.com/ssr-glue/vite-plugin/blob/755371d940fbea6365a38cab0f9c03e868f0db91/packages/playground/vue/vite.config.ts#L18-L27
- add
console.log
to log the ctx.filename, https://github.com/ssr-glue/vite-plugin/blob/755371d940fbea6365a38cab0f9c03e868f0db91/packages/vite-plugin/src/plugin.ts#L67-L78 then runyarn build
- goto
packages/playground/vue
runyarn dev
- goto http://localhost/landing-page/about to see the log
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Plugin API - Vite
Dedicated hook for transforming HTML entry point files such as index.html . The hook receives the current HTML string and a transform context....
Read more >Why does Javascript/Vite.js multi-page app fail on build?
When add home.html to my config file, the build breaks. I get an error saying: [vite:build-html] EISDIR: illegal operation on a directory, ...
Read more >React Redux Hooks Explained - Morioh
Hi guys, In this video I explained about React Redux Hooks.
Read more >Recommended - SlideShare
Dedicated hook for transforming HTML entry point files such as ... For production: after running vite build , a manifest.json file will.
Read more >Vue-CLI migration Vite2 - Programmer Sought
And Vite directly uses the HTML file, which will resolve the Script tag in the HTML to find ... transformIndexHtml Hook, receive the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you can use
middleware
in vite dev server to rewrite url what you want.so
/nested/**/*
will go to<root>/nested/index.html
I second @anncwb. Vite currently performs a simple fallback when the route
index.html
is not found. Resolving subpaths to their ownindex.html
(as shown in the issue description), feels like a special routing behaviour that should be implemented in userland via server middlewares. If Vite happens to support this today, it would be a breaking change too.