Skip to content

transformIndexHtml hook gets the wrong html filepath when running Multi-Page #2958

@yaquawa

Description

@yaquawa

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

  1. clone https://github.com/ssr-glue/vite-plugin
  2. run yarn
  3. remove comment https://github.com/ssr-glue/vite-plugin/blob/755371d940fbea6365a38cab0f9c03e868f0db91/packages/playground/vue/vite.config.ts#L18-L27
  4. 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 run yarn build
  5. goto packages/playground/vue run yarn dev
  6. goto http://localhost/landing-page/about to see the log

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions