Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in CSS output location #15141

Closed
7 tasks done
benmccann opened this issue Nov 26, 2023 · 9 comments · Fixed by #15154
Closed
7 tasks done

Regression in CSS output location #15141

benmccann opened this issue Nov 26, 2023 · 9 comments · Fixed by #15154

Comments

@benmccann
Copy link
Collaborator

benmccann commented Nov 26, 2023

Describe the bug

CSS is output to a different location. That location doesn't match the location in the manifest and the change in location breaks SvelteKit users upgrading to Vite 5 because it breaks relative links to font files and potentially other assets: sveltejs/kit#11085

We could work around it on the SvelteKit side by changing the left hand side of the input object in the Vite config, but the workarounds have some issues. E.g. I could replace / with _, but then the file names get to be awkwardly long and show up differently in the Chrome network tab. If I try to just strip the portion before / then I run into the danger of overwriting the input entries for files with the same name living in different directories.

Reproduction

https://github.com/benmccann/vite5-css-reproduction

Steps to reproduce

pnpm install && pnpm build

Vite 5 produces CSS at dist/assets/lib/example-XpY97b8p.css

Vite 4 produces CSS at dist/assets/example-507eca81.css

System Info

Vite 5.0.2 compared to Vite 4.5.0

Used Package Manager

pnpm

Logs

No response

Validations

@dominikg
Copy link
Contributor

if you set build.manifest to true in the vite.config.js of the reproduction and run pnpm build, it writes the manifest to
/dist/.vite/manifest.json

this contains

  "src/lib/example.js": {
    "assets": [
      "assets/fira-mono-cyrillic-ext-400-normal-dOGCK5uJ.woff2",
      /* ... */
    ],
    "css": [
      "assets/lib/example-XpY97b8p.css"
    ],
    "file": "lib/example-jnbdGhTu.js",
    "isDynamicEntry": true,
    "isEntry": true,
    "src": "src/lib/example.js"
  },

so in a nested entry, the information does exist.
Switching to vite4 shows the same entry (without the lib part, but moving around assets in build output should be fine as long as the manifest contains the correct references)

However, diffing the manifests generated by vite4 and vite5 shows that the vite5 manifest conains less top level entries, notably

  "src/assets/svelte.svg": {
  "file": "assets/svelte-a39f39b7.svg",
  "src": "src/assets/svelte.svg"
},
"src/lib/example.css": {
  "file": "assets/example-507eca81.css",
  "src": "src/lib/example.css"
},

are only present in vite4 manifest. It also looks like vite5 inlines the svelte svg into main js, while vite4 puts it in assets instead.

@dominikg
Copy link
Contributor

note to others looking at the names and wondering why they might be different, the vite.config.js in the reproduction has custom config https://github.com/benmccann/vite5-css-reproduction/blob/master/vite.config.js#L5

@dominikg
Copy link
Contributor

this mentions changes in the css manifest and sveltekit #14945 cc @bluwy

@benmccann
Copy link
Collaborator Author

benmccann commented Nov 26, 2023

The issue is that the CSS file is output in the wrong location. E.g. it's at assets/lib/example-XpY97b8p.css instead of assets/example-XpY97b8p.css. And because it's in the wrong location the relative import of font files is broken.

@benmccann benmccann changed the title Regression or undocumented breaking change in CSS output location Regression in CSS output location Nov 26, 2023
@benmccann
Copy link
Collaborator Author

this mentions changes in the css manifest and sveltekit #14945 cc @bluwy

Ooh. Yes, I suspect one of the commits on that PR in particular:

c2a750d: generate the filename based on the chunk name

@dominikg
Copy link
Contributor

dominikg commented Nov 26, 2023

this seems to be caused by the rollupOptions.input config for lib/example.js ... it's both an entry and a dynamic import (onMount of Counter.svelte). If you remove the entry from vite config, the css file is created in assets/ and the relative font links in example work as expected.

@sapphi-red
Copy link
Member

#15154 should fix the incorrect asset paths in CSS files.
#15155 changes the CSS output location, but I'm not sure if this should be merged.

@helhum
Copy link
Contributor

helhum commented Nov 27, 2023

However, diffing the manifests generated by vite4 and vite5 shows that the vite5 manifest conains less top level entries, notably

Is this an intentional change?

To illustrate the changes in manifest.json generation I created a minimal project.

--- a/dist/manifest.json
+++ b/dist/manifest.json
@@ -1,13 +1,9 @@
 {
-  "main.css": {
-    "file": "assets/main-829fb0a8.css",
-    "src": "main.css"
-  },
   "main.js": {
     "css": [
-      "assets/main-829fb0a8.css"
+      "assets/foo-sok_4qEN.css"
     ],
-    "file": "assets/foo-b8911e79.js",
+    "file": "assets/foo-TcdXag5j.js",
     "isEntry": true,
     "src": "main.js"
   }

This change breaks my backend integration with vite, as I need to find the css file that is related to JS entry point separately

@helhum
Copy link
Contributor

helhum commented Nov 27, 2023

I added a new ticket #15161 since this was initially related to a wrong asset URL

@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants