0
votes

I try to include lokiJS (locla json database) to my vue-electron app from a vue-cli-plugin-electron-builder!.

src/db/db.js

const path = require('path')
import * as loki from 'lokijs';
const dbPath = path.resolve('src/db/db.json')
let db = new loki(dbPath);
export default db

src/main.js

import db from './db/db'
Vue.prototype.$db = db

src/components/component.vue

created() {
    const db = this.$db;
    db.loadDatabase({}, () => {
      let rooms = db.getCollection("rooms");
      this.rooms = rooms.find({ activ: true });
    });
  }

If I work in dev mode all works fine but when I build electron production app is import db from './db/db' not include. Thank you!

1

1 Answers

0
votes

When you work in dev mode after build all the files kept inside the resource directory. like

                    app 
                     |-  dlls
                     |- app.exe
                     |- resources
                               |- app(folder)  all the JS files kept inside this.

But in case of prod

                   app 
                     |-  dlls
                     |- app.exe
                     |- resources
                               |- app.asar  all the JS files kept inside this zip.

so first check where to kep this and how you try to access this db file .

Hope it will work.