vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
65.92k stars 5.88k forks source link

CSS from entrypoints is not extracted correctly #17527

Open susnux opened 1 week ago

susnux commented 1 week ago

Describe the bug

I am using vite with JavaScript entry point.

If I have entry points with styles (e.g. Vue components) and also async styles (e.g. async Vue component), and I set build.cssCodeSplit: false then vite will not correctly extract the CSS.

For the async import the styles are loaded using module preload correctly. But for the entry points with static imports no CSS entry point is created, so I do not know which CSS file I need to add to my application.

Expected behavior:

Reproduction

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

Steps to reproduce

  1. Run npm ci && npx vite build
  2. See that there is neither a main.css nor a second.css but just some "randomly" named assets¹

¹ For bigger projects this might contain a lot of css assets with random names.

System Info

Does not matter, but:

  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:
    vite: ^5.3.1 => 5.3.1

Used Package Manager

npm

Logs

No response

Validations

stackblitz[bot] commented 1 week ago

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

susnux commented 1 week ago

I currently working on a workaround, but it is very unexpected that vite only can handle this with HTML input and not with JS input (meaning you currently have to guess which CSS to use with your JS entry).

My workaround plugin solution: https://github.com/nextcloud-libraries/nextcloud-vite-config/pull/204