vitejs / vite

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

During Legacy builds worker files are not generated with `renderModernChunks` set to false #18558

Open christowiz opened 1 week ago

christowiz commented 1 week ago

Describe the bug

I am trying to create a legacy-only build (no modern chunks) using the Legacy plugin that outputs working code which includes the web worker files.

What is happening is that when renderModernChunks is set to false the worker file is not created during the build but is still referenced inside the bundled code. When renderModernChunks is either set to true or absent from the config the worker files are generated correctly.

This works correctly in dev mode

From a cursory examination I found that if I removed the conditional inside the legacyPostPlugin.configResolved method the worker files are generated correctly and the index.html file is output correctly. I haven't had time to dig any deeper.

image

Note: The reason I need a legacy only build is the HTML that is generated which supports both legacy and modern does not work on older browsers. This is a separate issue.

Reproduction

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

Steps to reproduce

image

Testing

With Modern

Difference being the generated index.html file

System Info

## StackBlitz
  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.3 => 5.4.3 
    vite: ^5.4.10 => 5.4.10 

## Local
  System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 152.56 MB / 16.00 GB
    Shell: 5.9 - /opt/homebrew/bin/zsh
  Binaries:
    Node: 22.9.0 - ~/Library/pnpm/node
    npm: 10.9.0 - ~/Library/pnpm/npm
    pnpm: 9.7.1 - /opt/homebrew/bin/pnpm
    bun: 1.1.30 - ~/.bun/bin/bun
    Watchman: 2024.10.21.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 130.0.6723.92
    Chrome Canary: 132.0.6813.0
    Safari: 18.0
  npmPackages:
    @vitejs/plugin-legacy: 5.4.3 => 5.4.3 
    vite: 5.4.10 => 5.4.10

Used Package Manager

npm

Logs

No response

Validations

bluwy commented 1 week ago

Is this the same as https://github.com/vitejs/vite/issues/16639 (but english)?

christowiz commented 1 week ago

Is this the same as #16639 (but english)?

I guess it is (after viewing the translation). Looks like that is from May 8th with no comments.