How to create Vite based Vue component library consumable via .mjs files? #7673
Replies: 2 comments 1 reply
-
I faced the same problem. Do you have a solution to solve this problem? |
Beta Was this translation helpful? Give feedback.
-
This is tricky. Vite it telling you that it can't alayze this remote file. Usually, in apps, dynamic imports reference local files that Vite can analyze and, famongst other things, resolve package imports. It would for example replace As it can't analyze the remote library file, that remote library file contains a raw So you would need an import map in your |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I created a Vite based Vue library. This library should distribute a single component inside a .mjs file.
Library setup
I basically created a new Vue app via
npm create vue
, moved every dependency to dev dependencies and added this to the package.jsonAfter that I added the following to my vite.config.ts file
Building the project should generate you a computedRenderer.mjs in the dist directory ( as expected ).
File server for testing purposes
I created a small Node server serving the static .mjs file
When running the server and calling
you should get the file content
How I consume the component
In my main project I try to import the component dynamically during runtime like so
Unfortunately I get the following warning
and error
Is my library setup wrong? Or how can I consume the component via url?
Please let me know if you need more information
Beta Was this translation helpful? Give feedback.
All reactions