(i already posted this in #archived-plugins but did not get an answere there, so i hope you can help me here, sorry about posting twice)
I want to use this.emitFile in a plugin to add a css file to the bundle. I want to reference the bundled file in a json file, but this.getFilename does not return the path to the css file.
While debugging i found out that everything works as expected if I use a .js file instead of a .css file, which seems strange to me:
https://stackblitz.com/edit/vitejs-vite-zyevpt?file=vite.config.ts&terminal=dev
Run vite build in the reproduction. It will log assets/test-637cee31.js as the filename for the css file (this seems wrong), but can not find this file in the bundle, because in the bundle the file is renamed to css file with a different hash.
Change "test.css" in line 13 of vite.config.ts to "test.js" and the correct filename is logged, and the file will be found in the bundle.
What am I doing wrong?
#Plugin: this.emitFile with CSS file seems to be broken?
1 messages · Page 1 of 1 (latest)
https://github.com/vitejs/vite/pull/6629/files <- seems to be the solution to that problem: you can use renderChunk to look up chunk.viteMetadata.importedCss which contains the path to the css file in the bundle.