-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use a local database (SQLite or NeDB) after build? #76
Comments
The reason it doesn't work is because all of your files get packed into an Note: change // vue.config.js
module.exports = {
pluginOptions: {
electronBuilder: {
builderOptions: {
extraResources: ['src/database.txt']
}
}
}
} // Wherever you use the database
import path from 'path'
const isBuild = process.env.NODE_ENV === 'production'
const pathToDbFile = path.join(
(isBuild ? __dirname : __static),
(isBuild ? '../../' : ''),
'../src/database.txt'
)
UPDATE: const pathToDbFile = path.join(
isBuild ? __dirname : __static,
'../src/database.txt',
); |
Man, you are a life saver, thank you so much. |
@nklayman Thanks for this great plugin! I'm having a similar issue where I'm trying to use child_process.fork, but it doesn't seem to work in the bundled app. It only works from electron:serve. // vue.config.js
module.exports = {
configureWebpack: {
resolve: {
symlinks: false
}
},
pluginOptions: {
electronBuilder: {
extraResources: [
"src/imdone-repo-worker.js"
]
}
}
} // forking the worker
const pathToWorker = path.join(
(isDevelopment ? __static : __dirname),
(isDevelopment ? '' : '../../'),
'../src/imdone-repo-worker.js'
)
workers[this.path] = this.worker = fork(pathToWorker, {silent: true}) Any idea why this won't work? |
@piascikj have you tried placing the script in the public folder and running it inside the archive? Also, try just reading the contents of the file, or the parent directory. In addition, can you tell me where the worker file ends up in your built app? Thanks! |
Thanks a bunch @nklayman! Moving |
Thank you for this note! Is there any way this information could be made more visible or linked to in, for example the following page? https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/guide.html#native-modules Thanks! |
@nathansalwen Added a link to the above comment in that section, the updated docs should be live now. |
I see the comment. I think that is an improvement. In my case, the "extraResources" configuration was necessary for ffi-napi to find external libraries. Perhaps, the following text would be useful for others in my situation. "If files need to be present in an unpacked form, such as library files for ffi-napi or database files for MySQL or MongoDB, additional configuration is needed. See Issue #76 (comment) for usage of builderOptions->ExtraResources in vue.config.js." Again, thank you for an awesome tool! |
hi @nklayman, i'm having problems on building, can you be more specific about the configuration to use mysql? |
@douglast2t use mysql as if you are creating a regular nodejs script, but follow the instructions in #76 (comment) for determining the location of your database file/folder. The mysql code should go in |
this worked for me in vue.config.js
these could also be helpful for you https://stackoverflow.com/questions/40650701/nedb-not-loading-or-storing-to-file |
I'm trying to use a local database in my electron app, it works in development but when i bundled the app (I only tested in mac os bundle), the database is not connecting anymore, so maybe the bundle is not moving my database to a folder with the right permissions, but i dont know in what folder i can put my database file, i don't find nothing in the docs too, can someone help me with this?
The text was updated successfully, but these errors were encountered: