vitejs / vitejs/vite

CSS from entrypoints is not extracted correctly

Open
#17,527 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
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.css for the styles synchronously used by that entry point
  • Or create a entry-point-name.css with @import for the css chunks used synchronously by that entry point
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.