{"id":50922,"date":"2026-07-13T12:17:36","date_gmt":"2026-07-13T04:17:36","guid":{"rendered":"https:\/\/www.anzhuoe.com\/anzhuo\/?p=50922"},"modified":"2026-07-13T12:17:36","modified_gmt":"2026-07-13T04:17:36","slug":"js%e8%83%bd%e5%bc%80%e5%8f%91exe%e7%a8%8b%e5%ba%8f%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.anzhuoe.com\/anzhuo\/50922\/","title":{"rendered":"js\u80fd\u5f00\u53d1exe\u7a0b\u5e8f\u5417\uff1f"},"content":{"rendered":"<p>JavaScript \u901a\u5e38\u7528\u4e8e\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u7684\u4e3b\u8981\u7528\u9014\u662f\u5728\u6d4f\u89c8\u5668\u4e2d\u6dfb\u52a0\u4ea4\u4e92\u529f\u80fd\u3002\u7136\u800c\uff0c\u901a\u8fc7\u4f7f\u7528\u4e00\u4e9b\u7279\u5b9a\u7684\u6846\u67b6\u548c\u5de5\u5177\uff0c\u7684\u786e\u53ef\u4ee5\u7528JavaScript\u5f00\u53d1\u53ef\u6267\u884c\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff08.exe\uff09\u3002Electron \u662f\u4e00\u4e2a\u975e\u5e38\u53d7\u6b22\u8fce\u7684\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u8ba9\u4f60\u4f7f\u7528JavaScript\u3001HTML\u548cCSS\u5f00\u53d1\u8de8\u5e73\u53f0\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528 Electron \u5f00\u53d1\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>1. \u539f\u7406\uff1a<\/p>\n<p>Electron \u57fa\u4e8e Node.js \u548c Ch<a href=\"https:\/\/www.yimenexe.com\/ruanjian-kaifa-1317.html\">matlab\u600e\u4e48\u751f\u6210exe<\/a>romium\uff0c\u5b83\u5141\u8bb8\u4f60\u5728\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 JavaScript \u8fd0\u884c Node.js \u4ee3\u7801\uff0c\u540c\u65f6\u901a\u8fc7 Chromium \u7684 WebView <\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.yimenyun.net\/2023-03\/20\/11\/02093358119.jpg\" \/><\/figure>\n<\/p>\n<p>\u7ec4\u4ef6\u663e\u793a Web \u5185\u5bb9\u3002\u8fd9\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u4f7f\u7528\u719f\u6089\u7684 Web \u6280\u672f\u6808\u6765\u6784\u5efa\u539f\u751f\u5e94\u7528\u7a0b\u5e8f\u3002Electron\u901a\u8fc7\u6253\u5305 Node.js \u548c Chromium\uff0c\u5c06\u6bcf\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u5728\u72ec\u7acb\u7684\u684c\u9762\u7a97\u53e3\u4e2d\u3002\u8fd9\u610f\u5473\u7740\u4f60\u90e8\u7f72\u7ed9\u7528\u6237\u7684 Electron \u5e94\u7528\u7a0b\u5e8f\u5c06\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u3002<\/p>\n<p>2. \u8be6\u7ec6\u4ecb\u7ecd\u6b65\u9aa4\uff1a<\/p>\n<p>\uff081\uff09\u5b89\u88c5 Node.js\uff1a\u9996\u5148\u9700\u8981\u5b89\u88c5 Node.js\uff0c\u8bbf\u95eeNode.js\u5b98\u7f51(https:\/\/nodejs.org\/)\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002<\/p>\n<p>\uff082\uff09\u5b89\u88c5 Electron: \u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5 Electron\uff1a`npm install -g electron`<\/p>\n<p>\uff083\uff09\u521b\u5efa\u9879\u76ee\u6587\u4ef6\u5939\uff1a\u5728\u672c\u5730\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\uff0c\u7136\u540e\u8fdb\u5165\u5230\u8fd9\u4e2a\u6587\u4ef6\u5939\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u540d\u4e3a &#8220;my-electron-app&#8221; \u7684\u6587\u4ef6\u5939\uff0c\u7136\u540e\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\uff1a`cd my-electron-app`<\/p>\n<p>\uff084\uff09\u521d\u59cb\u5316\u9879\u76ee\uff1a\u5728\u9879\u76ee\u6587\u4ef6\u5939\u4e2d\uff0c\u5e76\u8fd0\u884c`npm init`\uff0c\u6309\u7167\u63d0\u793a\u751f\u6210 package.json \u6587\u4ef6\u3002\u8fd9\u4e2a\u6587\u4ef6\u5305\u542b\u4e86\u9879\u76ee\u7684\u57fa\u672c\u4fe1\u606f\u4ee5\u53ca\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n<p>\uff085\uff09\u5b89\u88c5\u9879\u76ee\u4e2d\u7684 Electron\uff1a\u8fd0\u884c`npm install electron &#8211;save<a href=\"https:\/\/www.yimenexe.com\/exe-kaifa-3841.html\">\u5feb\u5e94\u7528\u5f00\u53d1<\/a>-dev`\u5c06 Electron \u4f5c\u4e3a\u9879\u76ee\u5f00\u53d1\u4f9d\u8d56\u5b89\u88c5\u3002<\/p>\n<p>\uff086\uff09\u521b\u5efa\u4e3b\u6587\u4ef6\u548cHTML\u6587\u4ef6: \u5728\u9879\u76ee\u6587\u4ef6\u5939\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a &#8220;main.js&#8221; \u548c\u4e00\u4e2a &#8220;index.html&#8221; \u6587\u4ef6\u3002<\/p>\n<p>\uff087\uff09\u7f16\u5199\u4e3b\u6587\u4ef6 main.js: \u7f16\u5199 Electron \u5165\u53e3\u6587\u4ef6\uff0c\u5b9a\u4e49\u7a97\u53e3\u5927\u5c0f\uff0c\u52a0\u8f7d\u5e94\u7528\u7a0b\u5f0f\u7684HTML\u6587\u4ef6\u7b49\u3002<\/p>\n<p>&#8220;`javascript<\/p>\n<p>const { app, BrowserWindow } = require(&#8216;electron&#8217;);<\/p>\n<p>function createWindow() {<\/p>\n<p>  const win = new BrowserWindow({<\/p>\n<p>    width: 800,<\/p>\n<p>    height: 600,<\/p>\n<p>    webPreferences: {<\/p>\n<p>      nodeIntegration: true<\/p>\n<p>    }<\/p>\n<p>  });<\/p>\n<p>  win.loadFile(&#8216;index.html&#8217;);<\/p>\n<p>}<\/p>\n<p>app.whenReady().then(createWindow);<\/p>\n<p>app.on(&#8216;window-all-closed&#8217;, () =&gt; {<\/p>\n<p>  if (process.platform !== &#8216;darwin&#8217;) {<\/p>\n<p>    app.quit();<\/p>\n<p>  }<\/p>\n<p>});<\/p>\n<p>app.on(&#8216;activate&#8217;, () =&gt; {<\/p>\n<p>  if (BrowserWindow.getAllWindows().length === 0) {<\/p>\n<p>    createWindow();<\/p>\n<p>  }<\/p>\n<p>});<\/p>\n<p>&#8220;`<\/p>\n<p>\uff088\uff09\u7f16\u5199 HTML \u6587\u4ef6 (index.html)\uff1a<\/p>\n<p>&#8220;`html<\/p>\n<\/p>\n<p>\n<p>\n<p>    <title>Hello World!<\/title><\/p>\n<\/p>\n<p>\n<p>    Hello World!<\/p>\n<\/p>\n<p>&#8220;`<\/p>\n<p>\uff089\uff09\u4fee\u6539 package.json: \u4fee\u6539\u672a &#8220;main.js&#8221; \uff0c\u6dfb\u52a0 &#8220;start&#8221; \u811a\u672c\u3002<\/p>\n<p>&#8220;`json<\/p>\n<p>{<\/p>\n<p>  &#8220;name&#8221;: &#8220;my-electron-app&#8221;,<\/p>\n<p>  &#8220;version&#8221;: &#8220;1.0.0&#8221;,<\/p>\n<p>  &#8220;description&#8221;: &#8220;&#8221;,<\/p>\n<p>  &#8220;main&#8221;: &#8220;main.js&#8221;,<\/p>\n<p>  &#8220;scripts&#8221;: {<\/p>\n<p>    &#8220;start&#8221;: &#8220;electron .&#8221;<\/p>\n<p>  },<\/p>\n<p>  &#8220;author&#8221;: &#8220;&#8221;,<\/p>\n<p>  &#8220;license&#8221;: &#8220;ISC&#8221;,<\/p>\n<p>  &#8220;devDependencies&#8221;: {<\/p>\n<p>    &#8220;electron&#8221;: &#8220;^9.0.0&#8221;<\/p>\n<p>  }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\uff0810\uff09\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\uff1a\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\uff0c\u8f93\u5165`npm start`\uff0cElectron\u5e94\u7528\u7a0b\u5e8f\u5c06\u542f\u52a8\u663e\u793a &#8220;Hello World!&#8221; \u9875\u9762\u3002<\/p>\n<p>\uff0811\uff09\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\uff1a\u4e3a\u4e86\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528 &#8220;electron-packager&#8221; \u5de5\u5177\u3002\u9996\u5148\u5b89\u88c5\u5b83\uff1a`npm install electron-packager -g`\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a`electron-packager   &#8211;platform= &#8211;arch= &#8211;out= &#8211;overwrite`\u3002<\/p>\n<p><p>\u4f8b\u5982\uff1a`electron-packager . my-electron-app &#8211;platform=win32 &#8211;arch=x64 &#8211;out=release-builds &#8211;overwrite`<\/p>\n<p>\u8fd9\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a &#8216;.exe&#8217; \u6587\u4ef6\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u8be5\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u4f60\u7406\u89e3\u5982\u4f55\u4f7f\u7528 JavaScript\uff08Electron\u6846\u67b6\uff09 \u5f00\u53d1\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u3002<\/p>\n<p>        <\/\u8f93\u51fa\u76ee\u5f55><\/\u67b6\u6784><\/\u64cd\u4f5c\u7cfb\u7edf\u5e73\u53f0><\/\u5e94\u7528\u540d\u79f0><\/\u5e94\u7528\u76ee\u5f55><\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript \u901a\u5e38\u7528\u4e8e\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u7684\u4e3b\u8981\u7528\u9014\u662f\u5728\u6d4f\u89c8\u5668\u4e2d\u6dfb\u52a0\u4ea4\u4e92\u529f\u80fd\u3002\u7136\u800c\uff0c\u901a\u8fc7\u4f7f\u7528\u4e00\u4e9b\u7279\u5b9a\u7684\u6846\u67b6\u548c\u5de5\u5177\uff0c\u7684\u786e\u53ef\u4ee5\u7528JavaScript\u5f00\u53d1\u53ef\u6267\u884c\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff08.exe\uff09\u3002Ele<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[38750,38749,129,27,275],"topic":[],"class_list":["post-50922","post","type-post","status-publish","format-standard","hentry","category-ruanjiankaifa","tag-vbaexe","tag-vs2017cexe","tag-129","tag-27","tag-275"],"_links":{"self":[{"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/posts\/50922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/comments?post=50922"}],"version-history":[{"count":1,"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/posts\/50922\/revisions"}],"predecessor-version":[{"id":50959,"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/posts\/50922\/revisions\/50959"}],"wp:attachment":[{"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/media?parent=50922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/categories?post=50922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/tags?post=50922"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.anzhuoe.com\/anzhuo\/wp-json\/wp\/v2\/topic?post=50922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}