Skip to content

vite-plugin-lib-inject-css not working on SSR #12

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

Closed
pmrotule opened this issue Sep 7, 2023 · 4 comments · Fixed by #13
Closed

vite-plugin-lib-inject-css not working on SSR #12

pmrotule opened this issue Sep 7, 2023 · 4 comments · Fixed by #13

Comments

@pmrotule
Copy link
Contributor

pmrotule commented Sep 7, 2023

We are currently migrating our Vue component library from Rollup to Vite. We gave a try to vite-plugin-lib-inject-css which is working like a charm for the client assets, but it doesn't work for the server assets (build with the --ssr flag). It seems like it adds an import statement for the css file even though it doesn't exist (no CSS is generated on SSR which is expected).

I created a reproduction: https://stackblitz.com/edit/vue3-vite-starter-f7mk9t?file=dist%2Fserver%2FMyButton.mjs

Screenshot 2023-09-07 at 13 03 07

Of course, this breaks our SSR app that complains about the missing CSS files. One way to fix it would have been by using the SSR manifest generate with the --ssrManifest on client build, but it doesn't seem to work properly as the CSS file is sometimes missing. As you can see in my reproduction project, the entry HelloWorld doesn't have anything listed in the manifest:

image

So maybe vite-plugin-lib-inject-css could generate its own manifest and use it on SSR (e.g. by adding an option ssrManifestOutDir: '/absolute/path/to/dist/client' to retrieve the manifest on server build).

Can I suggest a solution by contributing a pull request? We are blocked by this issue so it's in our best interest to make it happen as soon as possible.

Thanks for the plugin by the way, it's a really nice solution to handle the CSS files 🙌

@emosheeep
Copy link
Owner

Of course sure, I'm trapped in my work and have no time to handle this for now, It would be fine if you have interest on it🎉

@emosheeep
Copy link
Owner

and I don't have much experience on ssr, i may need some days researching on it👀

@emosheeep
Copy link
Owner

vite-plugin-lib-inject-css (1.3.0) is published, you can have a try.

@pmrotule
Copy link
Contributor Author

It works as expected. Thank you 🙌

@emosheeep emosheeep added good first issue Good for newcomers and removed good first issue Good for newcomers labels May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants