{"id":7648,"date":"2023-10-19T15:45:19","date_gmt":"2023-10-19T07:45:19","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=7648"},"modified":"2023-10-19T15:45:19","modified_gmt":"2023-10-19T07:45:19","slug":"nodejs%e6%89%93%e5%8c%85dmg%e6%9c%89%e5%93%aa%e4%ba%9b%e6%96%b9%e6%b3%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2023\/10\/19\/nodejs%e6%89%93%e5%8c%85dmg%e6%9c%89%e5%93%aa%e4%ba%9b%e6%96%b9%e6%b3%95%ef%bc%9f\/","title":{"rendered":"nodejs\u6253\u5305dmg\u6709\u54ea\u4e9b\u65b9\u6cd5\uff1f"},"content":{"rendered":"
\u5728 macOS \u7cfb\u7edf\u4e2d\uff0cdmg \u662f\u4e00\u79cd\u5e38\u89c1\u7684\u5b89\u88c5\u5305\u683c\u5f0f\u3002\u5728 Node.js \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5e93\u6765\u6253\u5305 dmg\uff0c\u4f8b\u5982 appdmg\u3001electron-builder \u7b49\u3002\u672c\u6587\u5c06\u4ece\u539f\u7406\u548c\u4f7f\u7528\u4e24\u4e2a\u65b9\u9762\u4ecb\u7ecd Node.js \u6253\u5305 dmg\u3002<\/p>\n
## \u539f\u7406<\/p>\n
dmg \u662f macOS \u7cfb\u7edf\u4e2d\u7684\u4e00\u79cd\u955c\u50cf\u6587\u4ef6\u683c\u5f0f\uff0c\u7c7b\u4f3c\u4e8e Windows \u4e2d\u7684 iso \u6587\u4ef6\u3002dmg \u53ef\u4ee5\u5c06\u591a\u4e2a\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\u8fdb\u884c\u538b\u7f29\u548c\u52a0\u5bc6\uff0c\u65b9\u4fbf\u7528\u6237\u4e0b\u8f7d\u548c\u5b89\u88c5\u3002<\/p>\n
\u5728 Node.js \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5e93\u6765\u6253\u5305 dmg\uff0c\u4f8b\u5982 appdmg\u3001electron-builder \u7b49\u3002\u8fd9\u4e9b\u5e93\u7684\u672c\u8d28\u90fd\u662f\u901a\u8fc7\u8c03\u7528 macOS \u7cfb\u7edf\u4e2d\u7684\u4e00\u4e9b\u547d\u4ee4\u884c\u5de5\u5177\u6765\u5b8c\u6210 dmg \u6253\u5305\u7684\u3002<\/p>\n
\u5177\u4f53\u6765\u8bf4\uff0c\u6253\u5305 dmg \u7684\u8fc7\u7a0b\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n
1. \u521b\u5efa\u4e00\u4e2a\u7a7a\u7684 dmg \u6587\u4ef6\uff0c\u4f7f\u7528 hdiutil \u547d\u4ee4\u884c\u5de5\u5177\u521b\u5efa\u3002\u4f8b\u5982\uff1a<\/p>\n
“`bash<\/p>\n
hdiutil create -fs HFS+ -srcfolder \/path\/to\/files -volname “My App” myapp.dmg<\/p>\n
“`<\/p>\n
\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06 \/path\/to\/files \u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u540d\u4e3a myapp.dmg \u7684 dmg \u6587\u4ef6\uff0c\u5176\u4e2d -fs \u6307\u5b9a\u4e86\u6587\u4ef6\u7cfb\u7edf\u7c7b\u578b\uff0c-srcfolder \u6307\u5b9a\u4e86\u8981\u6253\u5305\u7684\u6587\u4ef6\u5939\uff0c-volname \u6307\u5b9a\u4e86 dmg \u6587\u4ef6\u7684\u5377\u6807\uff08\u5373\u663e\u793a\u5728 Finder \u7a97\u53e3\u4e2d\u7684\u540d\u79f0\uff09\u3002<\/p>\n
2. \u6302\u8f7d dmg \u6587\u4ef6\uff0c\u4f7f\u7528 hdiutil \u547d\u4ee4\u884c\u5de5\u5177\u8fdb\u884c\u6302\u8f7d\u3002\u4f8b\u5982\uff1a<\/p>\n
“`bash<\/p>\n
hdiutil attach myapp.dmg<\/p>\n
“`<\/p>\n
\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06 myapp.dmg \u6587\u4ef6\u6302\u8f7d\u5230 macOS \u7684\u6587\u4ef6\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 Finder \u6253\u5f00\u3002<\/p>\n
3. \u5c06\u9700\u8981\u5b89\u88c5\u7684\u6587\u4ef6\u590d\u5236\u5230 dmg \u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 cp \u547d\u4ee4\u6216\u8005\u5176\u4ed6\u65b9\u5f0f\u8fdb\u884c\u3002\u4f8b\u5982\uff1a<\/p>\n
“`bash<\/p>\n
cp \/path\/to\/myapp.app \/Volumes\/My\\ App\/<\/p>\n
“`<\/p>\n
\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06 \/path\/to\/myapp.app \u6587\u4ef6\u590d\u5236\u5230\u6302\u8f7d\u7684 dmg \u6587\u4ef6\u4e2d\u7684 My App \u76ee\u5f55\u4e0b\u3002<\/p>\n
4. \u5378\u8f7d dmg \u6587\u4ef6\uff0c\u4f7f\u7528 hdiutil \u547d\u4ee4\u884c\u5de5\u5177\u8fdb\u884c\u5378\u8f7d\u3002\u4f8b\u5982\uff1a<\/p>\n
“`bash<\/p>\n
hdiutil detach \/Volumes\/My\\ App\/<\/p>\n
“`<\/p>\n
\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5378\u8f7d My App \u76ee\u5f55\uff0c\u4f7f\u5f97 dmg \u6587\u4ef6\u53ef\u4ee5\u6b63\u5e38\u5173\u95ed\u548c\u4fdd\u5b58\u3002<\/p>\n
5. \u5bf9 dmg \u6587\u4ef6\u8fdb\u884c\u538b\u7f29\u548c\u52a0\u5bc6\u3002\u8fd9\u4e2a\u6b65\u9aa4\u53ef\u4ee5\u4f7f\u7528 hdiutil \u547d\u4ee4\u884c\u5de5\u5177\u5b8c\u6210\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u5de5\u5177\u5b8c\u6210\u3002\u4f8b\u5982\uff1a<\/p>\n
“`bash<\/p>\n
hdiutil convert myapp.dmg -format UDZO -o myapp-compressed.dmg<\/p>\n
“`<\/p>\n
\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06 myapp.dmg \u6587\u4ef6\u8f6c\u6362\u6210 UDZO \u683c\u5f0f\uff08\u5373\u538b\u7f29\u548c\u52a0\u5bc6\uff09\uff0c\u5e76\u4fdd\u5b58\u4e3a myapp-compressed.dmg \u6587\u4ef6\u3002<\/p>\n
\u4ee5\u4e0a\u5c31\u662f Node.js \u6253\u5305 dmg \u7684\u57fa\u672c\u539f\u7406\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 appdmg \u548c electron-builder \u4e24\u4e2a\u5e93\u6765\u6253\u5305 dmg\u3002<\/p>\n
## \u4f7f\u7528 appdmg<\/p>\n
appdmg \u662f\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u7684 Node.js \u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5feb\u901f\u6253\u5305 dmg\u3002\u5b83\u7684\u4f7f\u7528\u65b9\u5f0f\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u7f16\u5199\u4e00\u4e2a JSON \u914d\u7f6e\u6587\u4ef6\u5373\u53ef\u3002<\/p>\n
\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a config.json \u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n
“`json<\/p>\n
{<\/p>\n
“title”: “My App”,<\/p>\n
“icon”: “path\/to\/icon.icns”,<\/p>\n
“background”: “path\/to\/background.png”,<\/p>\n
“contents”: [<\/p>\n
{<\/p>\n
“x”: 192,<\/p>\n
“y”: 344,<\/p>\n
“type”: “file”,<\/p>\n
“path”: “path\/to\/myapp.app”<\/p>\n
},<\/p>\n
{<\/p>\n
“x”: 448,<\/p>\n
“y”: 344,<\/p>\n
“type”: “link”,<\/p>\n
“path”: “\/Applications”<\/p>\n
}<\/p>\n
],<\/p>\n
“window”: {<\/p>\n
“size”: {<\/p>\n
“width”: 540,<\/p>\n
“height”: 380<\/p>\n
}<\/p>\n
}<\/p>\n
}<\/p>\n
“`<\/p>\n
\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\u5305\u542b\u4e86\u4e00\u4e9b\u5fc5\u8981\u7684\u4fe1\u606f\uff0c\u4f8b\u5982\u6807\u9898\u3001\u56fe\u6807\u3001\u80cc\u666f\u3001\u5b89\u88c5\u6587\u4ef6\u7b49\u7b49\u3002\u5177\u4f53\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9\u6587\u6863\u3002<\/p>\n
\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u8c03\u7528 appdmg \u8fdb\u884c\u6253\u5305\uff1a<\/p>\n
“`javascript<\/p>\n