Access Capacitor API from store action ?
-
Hi,
Is it possible to access a Capacitor API e.g. Storage, from a Quasar store module action ?
I’m trying to populate state from Storage on app load (through prefetch) but I can’t seem to reference @capacitor/core.I was trying to do something like this in a store action (but it can’t get the dependency reference to capacitor/core)
import { Plugins } from '@capacitor/core' const { Storage } = Plugins export function getCompanyId (context) { const { companyId } = Storage.get({ key: 'companyId' }) context.commit('companyId', companyId) }
… but keep being met with errors like this even after playing around with the path
This dependency was not found: * @capacitor/core in ./src/store/appConfig/index.js, ./src/store/appConfig/actions.js
Anyone done anything similar or can suggest a better approach?
-
OK seems like it does work fine, it just won’t work with SPA build… doing some more tests
-
@tlloyduk since the dep is inside your src-capacitor/node_modules, you can use a relative path, or register an alias in quasar.conf.js to said folder. ie.
import { Plugins } from 'someAliasToSrcCapacitorNodeModulesFolder/@capacitor/core'
. tested on dev, but not sure if this work on production. -
Thanks metalsadman, I might experiment with that to see if I can run the app without the emulator for rapid dev
-
Using the app alias worked, e.g.
import { Plugins } from 'app/src-capacitor/node_modules/@capacitor/core'
Thanks
-
Thank you @tlloyduk
i use this lineimport { Plugins } from '../../src-capacitor/node_modules/@capacitor/core';
-
@Marin-Vartan Is there any reason not to install It separately outside src-capacitor?