Shareable Vite/Vue component - why am I getting error about missing CSS export? #13430
Unanswered
243riefsldjf
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Doing import 'mycomponent/dist/style.css' seems a bit silly to me as well, considering the goal is to export a self sufficient component. I imagine you could import 'style.css' inside the built .js file, then if someone installs the package they should have the styling. It feels like a very clinical idea, so I imagine there must be a better way to bundle it with Vite, rather than using some odd packages. I think rollupOptions should have a setting for bundling css with an individual file. But, so far I've seen very similar solutions to what you're describing. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello friends. I'm new to Vite and I'm hoping someone can help me with this.
I've been following this video to build a shareable Vue component via Vite, which I'm then testing by
npm link
ing it into another project.After building with Vite via
npm run bulid
and then linking, I end up with this structure in my other project'snode_modules
dir:I can successfully import my component - BUT it lacks CSS! So according to the above video I needed to do (in my
main.js
):I don't really want it to be globally available in this way, but I'm just trying to fix the CSS issue. Anyway, this results in the following error:
What am I doing wrong? Given my component was built as a SFC, why do I even need to import its CSS separately? And the file
/dist/style.css
does exist.Here's my component's
package.json
>exports
, incidentally:Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions