vite icon indicating copy to clipboard operation
vite copied to clipboard

CSS is missing after build.

Open ghost opened this issue 2 years ago • 2 comments

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

ghost avatar Oct 25 '22 09:10 ghost

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.

ghost avatar Oct 25 '22 09:10 ghost

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.

wallw-teal avatar Feb 03 '23 07:02 wallw-teal

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.

github-actions[bot] avatar Feb 18 '23 15:02 github-actions[bot]