<\/figure>\n<\/p>\n{<\/p>\n
width: 800,<\/p>\n
height: 600,<\/p>\n
webPreferences: {<\/p>\n
nodeIntegration: true<\/p>\n
}<\/p>\n
});<\/p>\n
\/\/\u8f7d\u5165\u4f60\u7684HTML5\u5e94\u7528\u7684index.html\u8fdb\u5165<\/p>\n
mainWindow.loadFile(‘index.html’);<\/p>\n
\/\/ \u5173\u95ed\u7a97\u53e3\u540e\u89e6\u53d1\u9000\u51fa\u5e94\u7528\u7684\u4e8b\u4ef6<\/p>\n
mainWindow.on(‘closed’, () => {<\/p>\n
mainWindow = null;<\/p>\n
});<\/p>\n
}<\/p>\n
\/\/ Electron \u4f1a\u89e6\u53d1”ready”\u4e8b\u4ef6\uff0c\u8868\u660e\u5e94\u7528\u7a0b\u5e8f\u5df2\u7ecf\u51c6\u5907\u597d\u4e86\u3002<\/p>\n
app.on(‘ready’, createWindow);<\/p>\n
\/\/ \u5f53\u6240\u6709\u7a97\u53e3\u90fd\u5df2\u5173\u95ed\uff0c\u5e94\u7528\u7a0b\u5e8f\u5c06\u9000\u51fa\u3002<\/p>\n
app.on(‘window-all-closed’, () => {<\/p>\n
if (process.platform !== ‘darwin’) {<\/p>\n
app.quit();<\/p>\n
}<\/p>\n
});<\/p>\n
app.on(‘activate’, () => {<\/p>\n
if (mainWindow === null) {<\/p>\n
createWindow();<\/p>\n
}<\/p>\n
});<\/p>\n
“`<\/p>\n
\u6b65\u9aa43: \u521b\u5efa\u4e00\u4e2aHTML5\u7f51\u9875\u5e94\u7528<\/p>\n
\u5982\u679c\u4f60\u5df2\u7ecf\u6709\u4e00\u4e2a\u7b26\u5408\u8981\u6c42\u7684HTML5\u5e94\u7528\uff0c\u8bf7\u5c06index.html\u53ca\u5176\u76f8\u5173\u8d44\u6e90\u6587\u4ef6\uff08\u5982JS\u548cCSS\u6587\u4ef6\uff09\u653e\u5230\u4f60\u7684\u9879\u76ee\u6587\u4ef6\u5939\u5185\u3002\u5982\u679c\u6ca1\u6709\uff0c\u8bf7\u521b\u5efa\u4e00\u4e2aindex.html\u53ca\u76f8\u5173\u8d44\u6e90\u6587\u4ef6\u3002<\/p>\n
\u6b65\u9aa44\uff1a\u8fd0\u884c\u548c\u6253\u5305\u5e94\u7528<\/p>\n
\u8fdb\u5165\u5230\u9879\u76ee\u6587\u4ef6\u5939\u76ee\u5f55\uff0c\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u53ef\u4ee5\u8fd0\u884c\u5e94\u7528\u5e76\u9884\u89c8\u6548\u679c\uff1a<\/p>\n
“`<\/p>\n
npm start<\/p>\n
“`<\/p>\n
\u5f53\u4f60\u786e\u8ba4\u5e94\u7528\u6b63\u5e38\u8fd0\u884c\u5e76\u60f3\u751f\u6210exe\u6587\u4ef6\u65f6\uff0c\u4f60\u9700\u8981\u5b89\u88c5\u4e00\u4e2a\u540d\u4e3a\u201celectron-builder\u201d\u7684\u6253\u5305\u5de5\u5177\u3002\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n
“`<\/p>\n
npm install electron-builder –save-dev<\/p>\n
“`<\/p>\n
\u5728\u4f60\u7684package.json\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n
“`json<\/p>\n
“scripts”: {<\/p>\n
\/\/…<\/p>\n
“pack”: “electron-builder –dir”,<\/p>\n
“dist”: “electron-builder”<\/p>\n
},<\/p>\n
“build”: {<\/p>\n
“appId”: “your.app.id”,<\/p>\n
“productName”: “Your App Name”,<\/p>\n
“win”: {<\/p>\n
“target”: [<\/p>\n
“nsis” \/\/\u4f60\u53ef\u4ee5\u6539\u4e3a\u5176\u4ed6windows\u5e73\u53f0\u652f\u6301\u7684\u7c7b\u578b\uff0c\u4f8b\u5982”portable”<\/p>\n
]<\/p>\n
}<\/p>\n
}<\/p>\n
“`<\/p>\n
\u73b0\u5728\u4f60vscode\u672a\u751f\u6210exe\u6587\u4ef6<\/a>\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5c06\u4f60\u7684HTML5\u5e94\u7528\u751f\u6210\u4e3aexe\u6587\u4ef6\uff1a<\/p>\n“`<\/p>\n
npm run dist<\/p>\n
“`<\/p>\n
\u6253\u5305\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u201cdist\u201d\u6587\u4ef6\u5939\u4e2d\u627e\u5230\u751f\u6210\u7684exe\u6587\u4ef6\u3002<\/p>\n
\u5230\u8fd9\u91cc\uff0cHTML5\u5c01\u88c5exe\u7684\u8fc7\u7a0b\u5df2\u7ecf\u5b8c\u6210\u3002\u73b0\u5728\u4f60\u53ef\u4ee5\u5c06exe\u6587\u4ef6\u5206\u53d1\u7ed9\u7528\u6237\u4f7f\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u5c06\u4e00\u4e2aHTML5\u7f51\u9875\u5e94\u7528\u5c01\u88c5\u5230\u4e00\u4e2a\u72ec\u7acb\u7684exe\u6587\u4ef6\u4e2d\u3002\u8fd9\u901a\u5e38\u4f1a\u5e26\u6765\u51e0\u4e2a\u4f18\u52bf\uff0c\u4f8b\u5982\u65b9\u4fbf\u5730\u5728\u4e0d\u540c\u7684\u8bbe\u5907\u4e0a\u8fd0\u884c\u3001\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u66f4\u81ea\u7136\u5730\u96c6\u6210\u4ee5\u53ca\u589e\u52a0\u81ea\u5b9a\u4e49\u7684\u529f\u80fd\u3002\u539f\u7406\uff1a\u5c06HTML5\u5e94\u7528<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1912,526,1032,1913,12],"topic":[],"class_list":["post-829","post","type-post","status-publish","format-standard","hentry","category-zhuomianruanjian","tag-nuitkaexe","tag-526","tag-1032","tag-32exe","tag-12"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=829"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/829\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=829"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}