\u7f51\u7ad9\u8f6cexe\u5de5\u5177<\/a><\/p>\nconst { 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(createWindow);<\/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 (BrowserWindow.getAllWindows().length === 0) {<\/p>\n
createWindow();<\/p>\n
}<\/p>\n
});<\/p>\n
“`<\/p>\n
\uff084\uff09\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a package.json \u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n
“`json<\/p>\n
{<\/p>\n
“name”: “my_h5_project”,<\/p>\n
“version”: “1.0.0”,<\/p>\n
“main”: “main.js”,<\/p>\n
“scripts”: {<\/p>\n
“start”: “electron .”<\/p>\n
}<\/p>\n
}<\/p>\n
“`<\/p>\n
\uff085\uff09\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\uff0c\u8fdb\u5165\u9879\u76ee\u6587\u4ef6\u5939 my_h5_project\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u5e94\u7528\uff1a<\/p>\n
“`shell<\/p>\n
npm start<\/p>\n
“`<\/p>\n
\uff086\uff09\u5c06 H5 \u7f51\u9875\u6253\u5305\u6210 EXE\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff08\u9700\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u8fd0\u884c\uff0c\u4f1a\u5728 dist \u6587\u4ef6\u5939\u4e0b\u751f\u6210 EXE \u6587\u4ef6\uff09\uff1a<\/p>\n
“`Shell<\/p>\n
npm install –save-dev electron-packager<\/p>\n
npx electron-packager . my-h5-exe –platform=win32 –arch=x64 –overwrite<\/p>\n
“`<\/p>\n
\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u4f7f\u7528 NW.js \u6216 Electron \u5c06 H5 \u7f51\u9875\u6253\u5305\u6210 Windows \u5e73\u53f0\u4e0a\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff08EXE\uff09\u4e86\u3002\u540c\u6837\u7684\u65b9\u6cd5\u53ef\u4ee5\u5c06\u5176\u6253\u5305\u6210 Mac \u548c Linux \u5e73\u53f0\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u4e00\u3001\u6982\u8ff0H5 \u662f\u4e00\u79cd\u7f51\u9875\u8bbe\u8ba1\u7684\u8bed\u8a00\uff0c\u4e3b\u8981\u5305\u62ec HTML5\u3001CSS3 \u548c JavaScript \u7b49\u6280\u672f\u3002\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\uff0c\u5f88\u591a\u4eba\u5e0c\u671b\u80fd\u628a H5 \u4f5c\u4e3a\u684c\u9762\u5e94\u7528\u6765\u4f7f\u7528\u3002\u56e0\u6b64\u51fa\u73b0\u4e86\u4e00\u4e9b\u53ef\u4ee5\u5c06 H5 \u6253\u5305\u6210 EX<\/p>\n","protected":false},"author":24,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[9255,9254,314,3640,322],"class_list":["post-4812","post","type-post","status-publish","format-standard","hentry","category-zuoexe","tag-exe","tag-9254","tag-314","tag-3640","tag-322"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/4812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=4812"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/4812\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=4812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=4812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=4812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}