I have an electron app that uses a static config.json file to hold individual client connections. When we reinstall the the app, say to a newer version, the file gets wiped in c:\programs{appname}. Is it possible to retain this static file on reinstall somehow? We're using electron-builder for the build.
I have been attempting to edit the nsis settings in the package.json file, our current set up is:
"nsis": {
"oneClick": false,
"perMachine": true,
"artifactName": "${productName} Setup.${ext}",
"uninstallDisplayName": "${productName}"
}
Related
We have a white-labeled app built with electron+angular and we want to build 3 different let's say 'flavours' of the app. Except for the UI changes in Angular we have a different electron-builder file with configurations for each project. The problem is that after I build the first one the next one is twice its size (as a .exe) and when I build the third one it's even bigger. It does not matter which I build first, as this is always the case.
I am building these apps with the electron-builder build command, using the --config option to pass a file with configurations.
This is the electron-builder file that I am using (with PROJECT_NAME, PROJECT_APP_ID, and PROJECT_ID changing depending on the project).
"productName": "<PROJECT_NAME>",
"appId": "<PROJECT_APP_ID>",
"directories": {
"output": "release/<PROJECT_ID>"
},
"files": [
"**/*",
"!**/*.ts",
"!*.code-workspace",
"!LICENSE.md",
"!package.json",
"!package-lock.json",
"!src/",
"!e2e/",
"!hooks/",
"!angular.json",
"!_config.yml",
"!karma.conf.js",
"!tsconfig.json",
"!tslint.json"
],
"win": {
"icon": "dist/assets/icons/<PROJECT_ID>"
},
"mac": {
"icon": "dist/assets/icons/<PROJECT_ID>"
},
"linux": {
"icon": "dist/assets/icons/<PROJECT_ID>"
},
}
Am I missing something for electron-builder? I am thinking maybe it keeps a 'cache' or something in a temporary folder and uses that to build on.
I know the question is a bit over the place, but I don't have experience with electron-builder. Any help or suggestion is welcomed.
Some details:
I tried building it from both a windows machine and mac os.
I am using electron-builder v22.9.1
I have tried using different folders for the result, it still didn't work.
[UPDATE] In the script that i use to build these projects, if i delete the directory of the build and then continue with the others, it will work.
We have a custom ExtJS CMD package created and used for main application. CMD package uses external js that is already minified/compressed. However on production build for app ExtJS again compresses already compressed file, leading to errors in app wherever those external resources are referenced.
Do we have any flag that turns of compression in package.json for externally included resources?
Well, one answer would be to simply not package the external JS with your app, but to serve it separately. Guessing that's not what you want to do, though...
So, to package the file and not have it be compressed, you edit the app.json. In particular, the production block, where there should be a js entry. Make it look something like this:
"production": {
"js": [
{"path": "app.js", "bundle": true},
{"path": "external_file_that_should_not_be_compressed.js", "compress": false }
],
...
},
I have a dll-file that I need to use for a separate process that is started by the Main process in my Electron project.
So I want to include this dll in my electron project and I'm using electron-builder to build the project. The problem is that I don't know how to include the file without it being added in the asar package, which is not reachable from the separate process directly. When I use app.getPath() to get the path for the running instance it will look something like this:
C:\installPath\myProject\resources\app.asar\my.dll
my electron-builder.json currently looks like this:
{
"productName": "myApp",
"directories": {
"output": "release/"
},
"files": [
"**/*",
"my.dll"
],
"win": {
"icon": "dist",
"artifactName": "myApp.${ext}",
"target": [
"portable"
]
}
}
Are there any way to get my.dll included in the resources folder (or somewhere else) instead of in the app.asar?
Thanks!
Solution1:
You should be able to do it with "extraResources" param, put your .dll under resources folder, then create config param named "extraResources" under targeted dist.
The installation process should copy the file(s) to app’s resources directory
https://www.electron.build/configuration/contents#extraresources
Solution2:
You can download .dll file from a web server then move it to the desired place with fs.
If you Keep the DLL file in the Dist folder, Electron-builder tool will include that file into the app.asar file.
This is the limitation of that because if you trying to load the dll file using ffi module or your own written native node module then it will not load the file from app.asar file. so you have to keep the dll file outside of the app.asar file manually or make this copy setup part of your build system.
On Mac, when I run my app from WebStorm, exiftool-vendored works great. However, when I build my app (I use electron-builder) and install it on the same Mac, it never returns, even just trying to get the version:
exiftool.version().then(version => writeBreadcrumb('exif', version))
In other words, no error is raised, and the then is never executed when running an installed version of my app, though it works fine running my app from WebStorm (with cd build && electron .)
What am I doing wrong? Is there an example anywhere of how to use exiftool-vendored in an electron app?
You should take a look at what the docs say about making it work with Electron:
How do you make this work with electron?
Electron is notoriously brittle and buggy, and is not officially supported by this package. Although PhotoStructure uses this package within electron, there's a nontrivial amount of auxiliary support code specific to that project to make it work smoothly.
If you're still anxious to try, here are some things to keep in mind:
Note that this package will spawn exiftool external processes, which means the exiftool-vendored.pl and exiftool-vendored.exe packages should be included in your asarUnpack. SmartUnpack might work, but if it doesn't use a pattern like node_modules/{exiftool-vendored.*}/**/*.
If you're requiring exiftool-vendored from within a webview, you're gonna have a bad time. Many things won't work due to a lack of node compatibility within electron.
__dirname at runtime from within an asar package after webpacking will be invalid, so don't rely on that.
— https://github.com/photostructure/exiftool-vendored.js/wiki/FAQ#how-do-you-make-this-work-with-electron
Since I never found a way to get exiftool-vendored to work with electron on Mac, I accepted the above answer, as essentially a warning to steer clear of exiftool-vendored for electron on Mac.
This answer is included for completeness, for those of us who need exiftool in an electron app for both Mac and Windows:
I used node-exiftool with these settings added in package.json for electron-builder:
"build": {
...
"win": {
...
"extraResources": "exiftoolwin/**/*"
},
"mac": {
...
"extraResources": "exiftool/**/*"
}
}
In the root of my project, I added folders exiftoolwin and exiftool. In exiftoolwin, I put exiftool.exe which I obtained by following the Windows Stand-Alone Executable instructions here, and in my exiftool folder I put exiftool and lib which I obtained by extracting the full perl distribution on Mac, as described on the same page.
Then, in my .jsx (I'm using React):
import exiftool from 'node-exiftool';
const exiftoolFolderAndFile = process.platform === 'win32' ? 'exiftoolwin/exiftool.exe' : 'exiftool/exiftool';
const exiftoolPath = path.resolve(__dirname, '../..', exiftoolFolderAndFile);
const ep = new exiftool.ExiftoolProcess(exiftoolPath);
Then I just use ep as described here.
This is working for us:
add this dependency:
"exiftool-vendored": "^15.2.0",
Update package.json "build" section for mac ( not needed for windows as far as we can see )
"build": {
"mac": {
...
"asarUnpack": [
"node_modules/exiftool-vendored/**" ,
"node_modules/exiftool-vendored.pl/**"
]
}
}
I need to keep some files (like my data.db file) when installing electron app, I can copy and paste it after installation of .exe, but is better to have it by default.
Is the a way to configure electron builder to keep files or directories after installation in the installation path?
Solved using the extraFiles option: https://www.electron.build/configuration/contents#extrafiles
If you want to keep certain folders when updating an Electron app, you can use the asarUnpack field in the app's package.json file. The asarUnpack field specifies a list of glob patterns that match the files and directories that should be unpacked when the app is packaged as an ASAR (Atom Shell Archive).
For example, to keep the assets and node_modules directories when updating the app, you can add the following lines to the package.json file:
"asarUnpack": [
"assets/*",
"node_modules/*"
]
This will cause the assets and node_modules directories to be extracted to a separate folder when the app is packaged, and they will not be overwritten when the app is updated.
Note that the asarUnpack field is only used when packaging the app as an ASAR. If you are not using ASAR packaging, you can use a different approach to preserve certain directories during updates.