-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Describe 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