CSS from entrypoints is not extracted correctly
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 82.9k
- Forks
- 8.8k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 61
Description
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:
- Either duplicate the styles in
entry-point-name.cssfor the styles synchronously used by that entry point - Or create a
entry-point-name.csswith@importfor the css chunks used synchronously by that entry point
Reproduction
https://stackblitz.com/edit/vitejs-vite-bagjfe?file=vite.config.js
Steps to reproduce
- Run
npm ci && npx vite build - See that there is neither a
main.cssnor asecond.cssbut 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked StackBlitz reproduction and vite.config.js, then run npm ci && npx vite build and inspect the generated CSS assets. The fix should make CSS entry files such as main.css or second.css available for styles synchronously used by each entry point when cssCodeSplit is false.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css, javascript
- Domain
- build-system, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100