vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.32k stars 1.01k forks source link

Possibility to add a custom icon on the generated package #151

Closed kennethpdev closed 3 years ago

kennethpdev commented 7 years ago

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.

sharathbaddam commented 7 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.

kennethpdev commented 7 years ago

@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.

tonywoode commented 7 years ago

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...

sharathbaddam commented 7 years ago

@tonywoode I was referring to this issue #91 when i said pkg > v4.

tonywoode commented 7 years ago

thanks - yes my comments above about Resource Hacker should now be redundant then...great!

soniagandhi commented 6 years ago

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.

KingRial commented 6 years ago

@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!

FrankenApps commented 4 years ago

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.

github-actions[bot] commented 3 years ago

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

github-actions[bot] commented 3 years ago

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.

ExordiumX commented 3 years ago

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.

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.

renandecarlo commented 3 years ago

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

cayank commented 3 years ago

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.

Alynva commented 3 years ago

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

renandecarlo commented 3 years ago

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.

This one https://www.icon-maker.com/download.htm

KK-Designs commented 3 years ago

@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 ?

cayank commented 3 years ago

@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 ?

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.

KK-Designs commented 3 years ago

ok thanks @cayank !

cayank commented 3 years ago

ok thanks @cayank !

You're welcome.

I2rys commented 3 years ago

Hello @cayank, Using your method in changing the compiled pkg icon doesn't seem to work. :/

fdciabdul commented 2 years ago

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

hp8wvvvgnj6asjm7 commented 2 years ago

why is this not built into pkg ?

Adeekonn commented 2 years ago

exactly it should be built in

elliot-huffman commented 2 years ago

Using resource hacker is a hack/workaround and not a best practice for enterprise environments...

Gu7z commented 2 years ago

It is a nice feature to have when working with production apps

@leerob Any plans to do this?

fdciabdul commented 2 years ago

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!'));
afalahi commented 2 years ago

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.

fdciabdul commented 2 years ago

just create a new file and run that , example node build.js

kennethpdev commented 1 year ago

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!

Kruithne commented 1 year ago

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

I2rys commented 1 year ago

The @angablue/exe saves the day because it works and thanks @fdciabdul

9de commented 1 year ago

The @angablue/exe doesn't work for me again

lmx99 commented 1 year ago

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

9de commented 1 year ago

Again Not working it's just close the app

fdciabdul commented 1 year ago

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

9de commented 1 year ago

Pkg: Error reading from file.

PythonCircuit commented 10 months ago

Just add the damn icon to pkg vercel or tell us why we should not use pkg at the top of this page.

KDot227 commented 10 months ago

bump