vite
vite copied to clipboard
CSS is missing after build.
Describe the bug
As title, my styles (including style tag in SFC and css imported) are missing when I compile my app in IIFE
format.
It works properly with vite serve
, but not vite build
. I saw the css emitted in other format, but not IIFE. For that, I can't load Vue
or other libraries (e.g. vue-i18n
, etc) form CDN, which I wanted to.
I have been tested in multiple environments, desktop and StackBlitz. I success to produce css file when the project has many rules, not sure how many is enough, I just tested with 1 of my old project. So the problem might be too less of css.
Reproduction
https://stackblitz.com/edit/vitejs-vite-zvjhr7
Steps to reproduce
Run npm install
followed by npm run build
and see dist
directory.
Style should be included but not.
System Info
System:
OS: Windows 10 10.0.19044
CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
Memory: 5.04 GB / 15.87 GB
Binaries:
Node: 16.18.0 - C:\ProgramData\scoop\apps\nodejs-lts\current\node.EXE
Yarn: 1.22.18 - C:\ProgramData\scoop\apps\nodejs-lts\current\bin\yarn.CMD
npm: 8.12.1 - C:\ProgramData\scoop\apps\nodejs-lts\current\bin\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (106.0.1370.52)
Used Package Manager
npm
Logs
vite v3.1.8 building for production... ✓ 18 modules transformed. dist/index.html 0.77 KiB dist/assets/index.e3272c7e.css 0.07 KiB / gzip: 0.09 KiB dist/assets/index.57aaac97.js 55.09 KiB / gzip: 22.19 KiB
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] 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.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Btw, I have found the solution for my situation. Just to turn build.cssCodeSplit
to false
in defineConfig
, it build with separated CSS. But I believe this might not be the expected behaviour, since that there will be a async chunk linked to link tag, which I can't find that too.
I think I am also running into this. vite build
worked completely worked under v3.1.8, but upgrading to v4.1.1 causes a particular set of styles not to be included in the output. vite dev
still works. Currently, that CSS file imported under some files which are code split by dynamic imports, but I pulled it all the way up to the top-level entry point and it still has the issue. Setting build.cssCodeSplit
to false
does seem to address the issue, but in my case that might be a rough ask since the code splitting was helping a lot with the initial load.
Hello @ghost. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction
will be closed if they have no activity within 3 days.