0

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!

Payam Khaninejad
  • 7,692
  • 6
  • 45
  • 55
Vin
  • 143
  • 1
  • 1
  • 7

1 Answers1

0

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.

Sunny Goel
  • 1,982
  • 2
  • 15
  • 21
  • Thank you for your approach. I'm working on the Mac, I should have said that before, sorry, please. And Dev i mean if i want to look at app fast, i use npm run electron: serve. If you want to see the code on [a github](https://github.com/vincent41/ZimmerArchiv2019.git) – Vin May 04 '19 at 06:21