Closed kennethpdev closed 3 years ago
You can add resources (icon) to executables on Windows (ResourceHacker, etc) with pkg >4.0.
If you are asking about having a resource file that pkg can directly refer to it while building executable, may be @igorklopov can answer it.
@sharathbaddam yes it should be while building the executable. I haven't tried ResourceHacker myself, but would love to try it. Thanks for your suggestion.
Resource Hacker worked for me on pkg executables, however you have to make sure the ico you're using is a specific and valid size or the executable corrupts.
@sharathbaddam I don't understand the point you are making: since ResourceHacker is external to pkg and run after pkg has generated an executable, why would the version of pkg be important? why must it be > v4?
For osx: you can wrap the executable pkg makes in an app bundle like so and give it an icon that way. But if you're just scripting, it might be easier to just package the js itself like so...
@tonywoode I was referring to this issue #91 when i said pkg > v4.
thanks - yes my comments above about Resource Hacker should now be redundant then...great!
Need help in setting the customized icon during packaging on windows using pkg.
I am packaging node service into exe using pkg (pkg package.json --output ./dist/test.exe) It sets the icon as nodejs icon. I also tried with pkg package.json --icon ./src/testIcon.ico --output ./dist/test.exe But still it sets the icon as default nodejs icon.
Can you please help in setting the customized icon while packaging using pkg.
I tried with ResourceHacker, it corrupts my exe.
@soniagandhi please understand that to "overwrite" the current iconset, you need to prepare an "iconset.ico" with the same "dimensions" (otherwise you'll overwrite also part of the real executable, corrupting it).
Currently the default "iconset.ico" is composed by the following dimensions:
If you create a new "iconset.ico"with different dimensions you corrupt the executable.
I used the following URL to create an "iconset.ico" with the correct dimensions.
After creating a correct "iconset.ico" I changed the icon using node-resourcehacker For example:
...
resourceHacker({
operation: 'addoverwrite',
input: 'PathToOriginalExe',
output: 'PatToUpdatedExe',
resource: 'PathToNew_iconset.ico',
resourceType: 'ICONGROUP',
resourceName: '1'
},
error => {
... callback to call when everything is done ...
}
);
I hope this can help you!
P.S. the ability to configure icon/details just using directly pkg would be very nice!
This is possible if you edit the node base binary in .pkg-cache
with ResourceHacker (not the executable) and then build your app again.
You can also edit stuff like manufacturer, etc. (Version Info).
The cache folder should be located in C:\Users\<username>\.pkg-cache\<version>\
be sure to edit the node binary, that you specified in --targets.
This was initially discussed here.
This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label
This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.
This is possible if you edit the node base binary in
.pkg-cache
with ResourceHacker (not the executable) and then build your app again. You can also edit stuff like manufacturer, etc. (Version Info). The cache folder should be located inC:\Users\<username>\.pkg-cache\<version>\
be sure to edit the node binary, that you specified in --targets. This was initially discussed here.
But the binary gets replaced as soon as you run the pkg command, since it downloads a new version of it. Thus reverting back to the green icon.
I only managed to change the icon in recent versions using the Icon Maker - Icon Changer software. It seems there is a new 256x256 dimension which messed things
I only managed to change the icon in recent versions using the Icon Maker - Icon Changer software. It seems there is a new 256x256 dimension which messed things
Hey, may I have the link of these softwares you are using? Thank you.
It would be wonderful if we could just remove the Node icon. In most cases I think it's better not to have an icon than to have the Node icon
I only managed to change the icon in recent versions using the Icon Maker - Icon Changer software. It seems there is a new 256x256 dimension which messed things
Hey, may I have the link of these softwares you are using? Thank you.
@soniagandhi please understand that to "overwrite" the current iconset, you need to prepare an "iconset.ico" with the same "dimensions" (otherwise you'll overwrite also part of the real executable, corrupting it).
Currently the default "iconset.ico" is composed by the following dimensions:
- 16x16
- 32x32
- 48x48
- 64x64
- 128x128
If you create a new "iconset.ico"with different dimensions you corrupt the executable.
I used the following URL to create an "iconset.ico" with the correct dimensions.
After creating a correct "iconset.ico" I changed the icon using node-resourcehacker For example:
... resourceHacker({ operation: 'addoverwrite', input: 'PathToOriginalExe', output: 'PatToUpdatedExe', resource: 'PathToNew_iconset.ico', resourceType: 'ICONGROUP', resourceName: '1' }, error => { ... callback to call when everything is done ... } );
I hope this can help you!
P.S. the ability to configure icon/details just using directly pkg would be very nice!
What do I put in input
and output
?
@soniagandhi please understand that to "overwrite" the current iconset, you need to prepare an "iconset.ico" with the same "dimensions" (otherwise you'll overwrite also part of the real executable, corrupting it). Currently the default "iconset.ico" is composed by the following dimensions:
- 16x16
- 32x32
- 48x48
- 64x64
- 128x128
If you create a new "iconset.ico"with different dimensions you corrupt the executable. I used the following URL to create an "iconset.ico" with the correct dimensions. After creating a correct "iconset.ico" I changed the icon using node-resourcehacker For example:
... resourceHacker({ operation: 'addoverwrite', input: 'PathToOriginalExe', output: 'PatToUpdatedExe', resource: 'PathToNew_iconset.ico', resourceType: 'ICONGROUP', resourceName: '1' }, error => { ... callback to call when everything is done ... } );
I hope this can help you! P.S. the ability to configure icon/details just using directly pkg would be very nice!
What do I put in
input
andoutput
?
You can put the path where you want to print.
Example, input -> Put the path to keep original exe "./original" output -> Updated exe file "./updated"
So you need to mkdir them first.
ok thanks @cayank !
ok thanks @cayank !
You're welcome.
Hello @cayank, Using your method in changing the compiled pkg icon doesn't seem to work. :/
Hello @cayank, Using your method in changing the compiled pkg icon doesn't seem to work. :/
same with me , the app crashed after changin the icon
why is this not built into pkg ?
exactly it should be built in
Using resource hacker is a hack/workaround and not a best practice for enterprise environments...
It is a nice feature to have when working with production apps
@leerob Any plans to do this?
Found the library to change the icon for pkg
@angablue/exe
const exe = require('@angablue/exe');
const build = exe({
entry: './index.js',
out: './reminder.exe',
pkg: [ '--public'], // Specify extra pkg arguments
version: '2.4.2',
target: 'node16-win-x64',
icon: './icon/reminder.ico', // Application icons must be in .ico format
properties: {
FileDescription: 'Abdul Muttaqin',
ProductName: 'Reminder',
LegalCopyright: 'Reminder https://taqin.tech',
OriginalFilename: 'Reminder.exe'
}
});
build.then(() => console.log('Build completed!'));
Found the library to change the icon for pkg
@angablue/exe
const exe = require('@angablue/exe'); const build = exe({ entry: './index.js', out: './reminder.exe', pkg: [ '--public'], // Specify extra pkg arguments version: '2.4.2', target: 'node16-win-x64', icon: './icon/reminder.ico', // Application icons must be in .ico format properties: { FileDescription: 'Abdul Muttaqin', ProductName: 'Reminder', LegalCopyright: 'Reminder https://taqin.tech', OriginalFilename: 'Reminder.exe' } }); build.then(() => console.log('Build completed!'));
I'm running into the same issue for a CLI I'm building for our SaaS app. Where do I define this code? I'm currently doing everything manually, but moving to gulp and github actions to automate the build process.
just create a new file and run that , example node build.js
after almost 6 years, I'm revisiting this issue 😀 and it's still not a built-in feature.
But anyway the @angablue/exe
helped, thanks a lot!
For people still running into these issues, the "problem" is that pkg
is writing the source code to the end of the binary and then referencing the exact location of that source code in the final file. When changing the icon file via resource editing, you're potentially shrinking or growing the binary, which changes the location of the source code - so then pkg
is now looking in the wrong location.
A better solution I haven't seen mentioned is to use resedit which comes in both a CLI and a package version. Specifically, take a look at the --no-grow
option (and keep --allow-shrink disabled). This is specifically designed for use cases such as pkg
.
https://github.com/jet2jet/resedit-js-cli https://github.com/jet2jet/resedit-js
The @angablue/exe
saves the day because it works and thanks @fdciabdul
The @angablue/exe doesn't work for me again
a better way to solve the problem
npm install rcedit --save
// build.js
const rcedit = require('rcedit')
/*
exePath is the path to the Windows executable to be modified.
options is an object that can contain following fields:
version-string - An object containing properties to change the exePath's version string.
file-version - File's version to change to.
product-version - Product's version to change to.
icon - Path to the icon file (.ico) to set as the exePath's default icon.
requested-execution-level - Requested execution level to change to, must be either asInvoker, highestAvailable, or requireAdministrator. See here for more details.
application-manifest - String path to a local manifest file to use. See here for more details.
Returns a Promise with no value.
*/
rcedit('./AIsvg.exe',{
icon:'./appfile/favicon.ico'
})
node build.js
Again Not working it's just close the app
Again Not working it's just close the app
try look up the error by opening the binary app with terminal or command line in windows
Pkg: Error reading from file.
Just add the damn icon to pkg vercel or tell us why we should not use pkg at the top of this page.
bump
I think it would be good if it can also add a custom icon for the exe file. I'm not sure if thats possible already but would be a good feature.