I am developing some Vue components that I would like to place in an NPM package. The problem that I am facing is that I have no idea how to publish components that rely on a Vuex module.
I have neatly placed all the code needed for this library of components into a separate Vuex module but how do I register my module when somebody imports my package?
A good start would be creating a plugin I guess but I would still need to check for a Vuex instance and somehow register my module.
I've seen plenty of tutorials on how to publish Vue components but not something more complex.
Any suggestions?
This is also a helpful reference for anyone trying to figure this out:
https://forum.vuejs.org/t/how-to-create-an-npm-package-of-a-vue-js-project-which-uses-vuex/14706/2
A key thing to notice here is the usage of:
store.registerModule('desiredModuleName', yourModule)
It is a bit hidden away in the API, but this allows you to register your Vuex module as long as users pass in their store.
https://vuex.vuejs.org/en/modules.html#dynamic-module-registration
You should be able to just ask the user to add your vuex module (expose it as part of your packages public api) to your modules. Maybe that could be done as part of the installation function as well (if you use the plugin approach).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With