node.js pkg打包更换icon



在python里面pyinstaller打包可以轻松设置icon,但是到了node.js里面试用pkg就没有相关设置了。设置方法如下:

const ResEdit = require('resedit');
const PELibrary = require('pe-library');
const fs = require('fs');


let data = fs.readFileSync('my.exe');
let exe = PELibrary.NtExecutable.from(data);
let res = PELibrary.NtExecutableResource.from(exe);

let iconFile = ResEdit.Data.IconFile.from(fs.readFileSync('my.ico'));

ResEdit.Resource.IconGroupEntry.replaceIconsForResource(
    res.entries,
    1,
    1033,
    iconFile.icons.map((item) => item.data)
);

res.outputResource(exe);
let newBinary = exe.generate();
fs.writeFileSync('new.exe', new Buffer(newBinary));

**my.exe 对应pkg打包后的exe文件
**my.ico 对应需要设置的icon图标
**new.exe 是新生成的替换图标后的exe文件