Import lodash into vuex

vuex

#1

Does anyone know how to import a lodash function into vuex so it is available in all modules?
I have a vuex store separated into namespaced modules, and would like to use lodash isEqual in some getters. Right now I am able to do it by doing import isEqual from "lodash.isequal"; in each module I want to use it in, but is there a way to import it once in vuex and have it available in all modules?

Thank you.


#2

No there isn’t, at least nothing clean. Being explicit about he imports that you use is a good thing anyway.


#3

Thank you for the quick reply @LinusBorg. I burned up a lot of time trying to figure something out. I thought maybe there was a way similar to when you set up a library as a plug-in and do Vue.use, and it is available in all of your components. Now I know that is not the case.


#4

Technically you could create a wrapper plugin to do this. Or just assign Lodash to the window, but as Linus said, it’s much better to be explicit with your imports. This allows tree shaking as well, which a plugin or window would not so you could end up with code bloat.