{"id":2010,"date":"2023-08-04T15:47:56","date_gmt":"2023-08-04T07:47:56","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=2010"},"modified":"2023-08-04T15:47:56","modified_gmt":"2023-08-04T07:47:56","slug":"h5%e8%bd%ac%e6%88%90exe%e5%b8%b8%e7%94%a8%e5%b7%a5%e5%85%b7%e6%8e%a8%e8%8d%90","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/2010\/","title":{"rendered":"h5\u8f6c\u6210exe\u5e38\u7528\u5de5\u5177\u63a8\u8350"},"content":{"rendered":"

H5\uff08HTML5\uff09\u662f\u4e00\u79cd\u7528\u4e8e\u6784\u5efa\u7f51\u9875\u7684\u6807\u51c6\uff0c\u5b83\u5df2\u7ecf\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8eWeb\u5f00\u53d1\u9886\u57df\u3002\u4f46\u662f\uff0c\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5c06H5\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\uff09\uff0c\u8fd9\u6837\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728\u672c\u5730\u8fd0\u884c\uff0c\u800c\u4e0d\u5fc5\u4f9d\u8d56\u4e8e\u6d4f\u89c8\u5668\u3002\u4e0b\u9762\uff0c\u6211\u5c06\u4ecb\u7ecdH5\u8f6c\u6362\u4e3aexe\u7684\u539f\u7406\u548c\u8be6\u7ec6\u8fc7\u7a0b\u3002<\/p>\n

\u4e00\u3001H5\u8f6c\u6362\u4e3aexe\u7684\u539f\u7406<\/p>\n

H5\u8f6c\u6362\u4e3aexe\u7684\u539f\u7406\u662f\u5c06H5\u9875\u9762\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4f7f\u5176\u80fd\u591f\u5728\u672c\u5730\u72ec\u7acb\u8fd0\u884c\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u6d89\u53ca\u5230\u4e24\u4e2a\u4e3b\u8981\u7684\u6280\u672f\uff1aElectron\u548cNW.js\u3002<\/p>\n

Electron\u662f\u7531GitHub\u5f00\u53d1\u7684\u4e00\u4e2a\u5f00\u6e90\u6846\u67b6\uff0c\u5b83\u57fa\u4e8eNode.js\u548cChromium\u6d4f\u89c8\u5668\uff0c\u53ef\u4ee5\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002Electron\u63d0\u4f9b\u4e86\u8bb8\u591aAPI\uff0c\u5305\u62ec\u6587\u4ef6\u7cfb\u7edf\u3001\u7f51\u7edc\u3001\u7a97\u53e3\u7ba1\u7406\u7b49\uff0c\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06Web\u6280\u672f\u5e94\u7528\u4e8e\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\u3002<\/p>\n

NW.js\uff08\u524d\u8eab\u4e3aNode-Webkit\uff09\u662f\u53e6\u4e00\u4e2a\u5f00\u6e90\u6846\u67b6\uff0c\u4e5f\u53ef\u4ee5\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002NW.js\u4e0eElectron\u7c7b\u4f3c\uff0c\u57fa\u4e8eNode.js\u548cChromium\u6d4f\u89c8\u5668\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591aAPI\u548c\u6a21\u5757\uff0c\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06Web\u6280\u672f\u5e94\u7528\u4e8e\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\u3002<\/p>\n

\u4e8c\u3001H5\u8f6c\u6362\u4e3aexe\u7684\u8be6\u7ec6\u8fc7\u7a0b<\/p>\n

\u4e0b\u9762\uff0c\u6211\u5c06\u4ecb\u7ecd\u4f7f\u7528Electron\u5c06H5\u8f6c\u6362\u4e3aexe\u7684\u8be6\u7ec6\u8fc7\u7a0b\u3002\u8fd9\u91cc\u4ee5Windows\u64cd\u4f5c\u7cfb\u7edf\u4e3a\u4f8b\u3002<\/p>\n

\u6b65\u9aa4\u4e00\uff1a\u5b89\u88c5Node.js\u548cElectron<\/p>\n

\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5Node.js\u548cElectron\u3002Node.js\u662fElectron\u7684\u57fa\u7840\uff0c\u6240\u4ee5\u5fc5\u987b\u5148\u5b89\u88c5Node.js\u3002Node.js\u7684\u5b89\u88c5\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u4ece\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u5305\u5e76\u5b89\u88c5\u5373\u53ef\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Electron\uff1a<\/p>\n

“`<\/p>\n

npm install -g electron<\/p>\n

“`<\/p>\n

\u6b65\u9aa4\u4e8c\uff1a\u521b\u5efa\u6253\u5305deb\u5de5\u5177<\/a>\u9879\u76ee<\/p>\n

\u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\uff0c\u5e76\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amain.js\u7684\u6587\u4ef6\u3002main.js\u662fElectron\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u6587\u4ef6\uff0c\u5b83\u8d1f\u8d23\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u7a97\u53e3\u548c\u5904\u7406\u7a97\u53e3\u4e8b\u4ef6\u7b49\u3002<\/p>\n

\u5728main.js\u4e2d\uff0c\u9700\u8981\u5f15\u5165Electron\u6a21\u5757\uff0c\u5e76\u521b\u5efa\u4e00\u4e2aBrowserWindow\u5bf9\u8c61\u6765\u663e\u793aH5\u9875\u9762\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684main.js\u6587\u4ef6\u7684\u4f8b\u5b50\uff1a<\/p>\n

“`<\/p>\n

const { app, BrowserWindow } = require(‘electron’)<\/p>\n

function createWindow () {<\/p>\n

const win = new BrowserWindow({<\/p>\n

width: 800,<\/p>\n

height: 600,<\/p>\n

webPreferences: {<\/p>\n

nodeIntegration: true<\/p>\n

}<\/p>\n

})<\/p>\n

win.loadFile(‘index.html’)<\/p>\n

}<\/p>\n

app.whenReady().then(() => {<\/p>\n

createWindow()<\/p>\n

app.on(‘activate’, () => {<\/p>\n

if (BrowserWindow.getAllW<\/p>\n

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

indows().length === 0) {<\/p>\n

createWindow()<\/p>\n

}<\/p>\n

})<\/p>\n

})<\/p>\n

app.on(‘window-all-closed’, () => {<\/p>\n

if (process.platform !== ‘darwin’) {<\/p>\n

app.quit()<\/p>\n

}<\/p>\n

})<\/p>\n

“`<\/p>\n

\u5728\u4ee5\u4e0a\u4ee3\u7801\u4e2d\uff0c\u9996\u5148\u5f15\u5165\u4e86Electron\u6a21\u5757\uff0c\u5e76\u521b\u5efa\u4e86\u4e00\u4e2acreateWindow\u51fd\u6570\u6765\u521b\u5efa\u7a97\u53e3\u3002\u5728createWindow\u51fd\u6570\u4e2d\uff0c\u521b\u5efa\u4e86\u4e00\u4e2aBrowserWindow\u5bf9\u8c61\uff0c\u5e76\u8bbe\u7f6e\u4e86\u7a97\u53e3\u7684\u5927\u5c0f\u548cH5\u9875\u9762\u7684\u6587\u4ef6\u540d\uff08\u8fd9\u91cc\u662findex.html\uff09\u3002\u6700\u540e\uff0c\u4f7f\u7528app.whenReady()\u65b9\u6cd5\u6765\u521b\u5efa\u7a97\u53e3\uff0c\u5e76\u5728\u7a97\u53e3\u5173\u95ed\u65f6\u9000\u51fa\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u6b65\u9aa4\u4e09\uff1a\u6253\u5305\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u6700\u540e\u4e00\u6b65\u662f\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528Electron\u63d0\u4f9b\u7684electron-packager\u6a21\u5757\u6765\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u547d\u4ee4\u884c\u793a\u4f8b\uff1a<\/p>\n

“`<\/p>\n

electron-packager . MyApp –platform=win32 –arch=x64 –icon=.\/icon.ico<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c\u201c.\u201d\u8868\u793a\u5f53\u524d\u76ee\u5f55\uff0c\u201cMyApp\u201d\u662f\u5982\u4f55\u5c06jframe\u9879\u76ee\u6253\u5305\u6210exe\u6267\u884c\u6587\u4ef6<\/a>\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\uff0c\u201c–platform=win32\u201d\u8868\u793a\u6253\u5305\u6210Windows\u5e73\u53f0\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u201c–arch=x64\u201d\u8868\u793a\u4f7f\u752864\u4f4d\u67b6\u6784\uff0c\u201c–icon=.\/icon.ico\u201d\u8868\u793a\u4f7f\u7528\u4e00\u4e2a\u540d\u4e3aicon.ico\u7684\u56fe\u6807\u6587\u4ef6\u3002<\/p>\n

\u6253\u5305\u5b8c\u6210\u540e\uff0c\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a\u540d\u4e3aMyApp-win32-x64\u7684\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u53ef\u6267\u884c\u6587\u4ef6\u548c\u76f8\u5173\u6587\u4ef6\u3002\u53cc\u51fb\u53ef\u6267\u884c\u6587\u4ef6\u5373\u53ef\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

H5\u8f6c\u6362\u4e3aexe\u7684\u8fc7\u7a0b\u6d89\u53ca\u5230\u4e24\u4e2a\u4e3b\u8981\u7684\u6280\u672f\uff1aElectron\u548cNW.js\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4ecb\u7ecd\u4e86\u4f7f\u7528Electron\u5c06H5\u8f6c\u6362\u4e3aexe\u7684\u8be6\u7ec6\u8fc7\u7a0b\uff0c\u5305\u62ec\u5b89\u88c5Node.js\u548cElectron\u3001\u521b\u5efa\u9879\u76ee\u548c\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u3002\u901a\u8fc7\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06H5\u9875\u9762\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u65b9\u4fbf\u5730\u5728\u672c\u5730\u72ec\u7acb\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

H5\uff08HTML5\uff09\u662f\u4e00\u79cd\u7528\u4e8e\u6784\u5efa\u7f51\u9875\u7684\u6807\u51c6\uff0c\u5b83\u5df2\u7ecf\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8eWeb\u5f00\u53d1\u9886\u57df\u3002\u4f46\u662f\uff0c\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5c06H5\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\uff09\uff0c\u8fd9\u6837\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728\u672c\u5730\u8fd0\u884c\uff0c\u800c\u4e0d\u5fc5\u4f9d\u8d56\u4e8e\u6d4f\u89c8\u5668\u3002\u4e0b\u9762\uff0c\u6211\u5c06\u4ecb\u7ecdH5\u8f6c<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[4282,4281,256,12,300],"topic":[],"class_list":["post-2010","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-dmg","tag-exe","tag-256","tag-12","tag-300"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2010","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\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=2010"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2010\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=2010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=2010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=2010"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=2010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}