vitejs / vite

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

`@vitejs/plugin-legacy` injects scripts into html files without any JS in `mpa` mode #17943

Open kaciakmaciak opened 2 months ago

kaciakmaciak commented 2 months ago

Describe the bug

In mpa mode, the legacy scripts are injected into html pages which have no javascript in it.

Reproduction

https://stackblitz.com/edit/vitejs-vite-uysirc

Steps to reproduce

Run:

npm install
npm run build

Observe the dist/blank.html file. It contains the legacy scripts even though the blank.html does not have any JS endpoint.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-legacy: ^5.4.1 => 5.4.2 
    vite: ^5.4.1 => 5.4.2

Used Package Manager

npm

Logs

No response

Validations

stackblitz[bot] commented 2 months ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.