{"id":7072,"date":"2023-10-19T15:45:19","date_gmt":"2023-10-19T07:45:19","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=7072"},"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.yimenyun.cn\/emen\/7072\/","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

const appdmg = reexe\u6587\u4ef6\u8f6f\u4ef6<\/a>quire(‘appdmg’);<\/p>\n

const dmg = appdmg({<\/p>\n

source: ‘path\/to\/config.json’,<\/p>\n

target: ‘path\/to\/myapp.dmg’<\/p>\n

});<\/p>\n

dmg.on(‘finish’, () => {<\/p>\n

console.log(‘dmg created’);<\/p>\n

});<\/p>\n

dmg.on(‘error’, err => {<\/p>\n

console.error(err);<\/p>\n

});<\/p>\n

\n

<\/figure>\n<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u4ee3\u7801\u4f1a\u8bfb\u53d6 config.json \u6587\u4ef6\uff0c\u5e76\u5c06\u6253\u5305\u540e\u7684 dmg \u6587\u4ef6\u4fdd\u5b58\u4e3a myapp.dmg\u3002<\/p>\n

\u4f7f\u7528 appdmg \u6253\u5305 dmg \u975e\u5e38\u7b80\u5355\uff0c\u4f46\u662f\u5b83\u7684\u529f\u80fd\u6bd4\u8f83\u6709\u9650\uff0c\u65e0\u6cd5\u6ee1\u8db3\u4e00\u4e9b\u9ad8\u7ea7\u9700\u6c42\u3002\u5982\u679c\u9700\u8981\u66f4\u591a\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 electron-builder\u3002<\/p>\n

## \u4f7f\u7528 electron-builde\u6587\u4ef6\u5939\u5c01\u88c5exe\u53ef\u6267\u884c\u6587\u4ef6<\/a>r<\/p>\n

electron-builder \u662f\u4e00\u4e2a\u57fa\u4e8e Electron \u7684\u6253\u5305\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u6253\u5305\u5404\u79cd\u7c7b\u578b\u7684\u5e94\u7528\u7a0b\u5e8f<\/p>\n","protected":false},"excerpt":{"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<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[12633,7084,52,14,16],"topic":[],"class_list":["post-7072","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-mac","tag-urlexe","tag-52","tag-14","tag-16"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/7072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=7072"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/7072\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=7072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=7072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=7072"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=7072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}