vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.73k stars 6.21k forks source link

dev server cannot fallback to the corresponding `index.html when MPA entry points are specified #18726

Closed zheung closed 1 day ago

zheung commented 1 day ago

Describe the bug

In latest version 5.4.11, under dev, if index.html is missing from the preview path, entry points could not fallback to corresponding index.html. It always fallbacks to index.html in the root.

Minimal vite config:

import { resolve } from 'path';

export default {
    build: {
        target: 'esnext',
        rollupOptions: {
            input: {
                'a': resolve(__dirname, 'a', 'index.html'),
                'b': resolve(__dirname, 'a', 'b', 'index.html'),
            },
        },
    },
};
Maybe the table will help me express issue more clearly: Request Expected Current Matched?
/ /index.html /index.html yes
/a /a/index.html /index.html no
/a/index.html /a/index.html /a/index.html yes
/a/b /a/b/index.html /index.html no
a/b/index.html /a/b/index.html /a/b/index.html yes

The link for reproduction is also ready.

Although adding index.html to the end of the path is fine for previewing and debugging. But I don't think it's very intuitive to use. This section of the official guide supports my view: Align dev and preview HTML serving behaviour

Reproduction

https://stackblitz.com/edit/vitejs-vite-n8tdia?file=vite.config.js

Steps to reproduce

No response

System Info

System:
  OS: Windows 11 10.0.22631
  CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700
  Memory: 15.24 GB / 31.70 GB
Binaries:
  Node: 20.18.0 - D:\runtime\node\node.EXE
  npm: 10.8.2 - D:\runtime\node\npm.CMD
  pnpm: 9.14.2 - ~\AppData\Roaming\npm\pnpm.CMD
Browsers:
  Edge: Chromium (127.0.2651.74)
  Internet Explorer: 11.0.22621.3527
npmPackages:
  vite: ^5.4.0 => 5.4.11

Used Package Manager

pnpm

Logs

No response

Validations

sapphi-red commented 1 day ago

Your reproduction shows 404.

This section of the official guide supports my view: Align dev and preview HTML serving behaviour

I don't think so. Quoting the related rows of the table in that docs:

Request Before (dev) Before (preview) After (dev & preview)
/dir /index.html (SPA fallback) /dir/index.html /index.html (SPA fallback)
/dir/ /dir/index.html /dir/index.html /dir/index.html

If I expand your expectation table, it will be:

Request Your Expectation Current
/ /index.html /index.html
/a /a/index.html /index.html
/a/ - /a/index.html
/a/index.html /a/index.html /a/index.html
/a/b /a/b/index.html /index.html
/a/b/ - /a/b/index.html
a/b/index.html /a/b/index.html /a/b/index.html

The best way does not exist here as all hosting providers' behavior differs: https://github.com/slorber/trailing-slash-guide The current behavior is what we thought the safest.

zheung commented 1 day ago

Your reproduction shows 404.

This section of the official guide supports my view: Align dev and preview HTML serving behaviour

I don't think so. Quoting the related rows of the table in that docs:

Request Before (dev) Before (preview) After (dev & preview) /dir /index.html (SPA fallback) /dir/index.html /index.html (SPA fallback) /dir/ /dir/index.html /dir/index.html /dir/index.html If I expand your expectation table, it will be:

Request Your Expectation Current / /index.html /index.html /a /a/index.html /index.html /a/ - /a/index.html /a/index.html /a/index.html /a/index.html /a/b /a/b/index.html /index.html /a/b/ - /a/b/index.html a/b/index.html /a/b/index.html /a/b/index.html The best way does not exist here as all hosting providers' behavior differs: https://github.com/slorber/trailing-slash-guide The current behavior is what we thought the safest.

reproduction link has been fixed, refresh issuse pls.

zheung commented 1 day ago

Your reproduction shows 404.

This section of the official guide supports my view: Align dev and preview HTML serving behaviour

I don't think so. Quoting the related rows of the table in that docs:

Request Before (dev) Before (preview) After (dev & preview) /dir /index.html (SPA fallback) /dir/index.html /index.html (SPA fallback) /dir/ /dir/index.html /dir/index.html /dir/index.html If I expand your expectation table, it will be:

Request Your Expectation Current / /index.html /index.html /a /a/index.html /index.html /a/ - /a/index.html /a/index.html /a/index.html /a/index.html /a/b /a/b/index.html /index.html /a/b/ - /a/b/index.html a/b/index.html /a/b/index.html /a/b/index.html The best way does not exist here as all hosting providers' behavior differs: https://github.com/slorber/trailing-slash-guide The current behavior is what we thought the safest.

Oh this is my fault. Other mistakes in my actual project and not reading that quoted document carefully led me to the wrong conclusion. Thanks for the answer!