{"id":38183,"date":"2025-08-07T15:39:47","date_gmt":"2025-08-07T07:39:47","guid":{"rendered":"https:\/\/app.60day.cn\/appday\/?p=38183"},"modified":"2025-08-07T15:39:47","modified_gmt":"2025-08-07T07:39:47","slug":"%e5%89%8d%e7%ab%af%e5%ba%94%e7%94%a8%e6%89%93%e5%8c%85exe%e6%8e%a8%e8%8d%90%e4%b8%80%e9%97%a8%e6%89%93%e5%8c%85","status":"publish","type":"post","link":"https:\/\/app.60day.cn\/appday\/kaifaexe\/38183\/","title":{"rendered":"\u524d\u7aef\u5e94\u7528\u6253\u5305exe\u63a8\u8350\u4e00\u95e8\u6253\u5305"},"content":{"rendered":"<p>\u524d\u7aef\u5e94\u7528\u6253\u5305\u6210\u53ef\u6267\u884c\u7a0b\u5e8f\uff08exe\uff09\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728 Windows \u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u5206\u53d1\u548c\u5b89\u88c5\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u524d\u7aef\u5e94\u7528\u6253\u5305\u6210 exe \u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n<p>\u4e00\u3001\u539f\u7406<\/p>\n<p>\u524d\u7aef\u5e94\u7528\u6253\u5305\u6210 exe \u7684\u539f\u7406\u662f\u5c06\u524d\u7aef\u5e94\u7528\u7684\u4ee3\u7801\u548c\u8d44\u6e90\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u540c\u65f6\u5c06\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684 Web \u670d\u52a1\u5668\u5d4c\u5165\u5230\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002\u5f53\u7528\u6237\u8fd0\u884c\u8be5\u53ef\u6267\u884c\u6587\u4ef6\u65f6\uff0c\u8be5 Web \u670d\u52a1\u5668\u4f1a\u81ea\u52a8\u542f\u52a8\uff0c\u5e76\u5c06\u524d\u7aef\u5e94\u7528\u7684\u4ee3\u7801\u548c\u8d44\u6e90\u6587\u4ef6\u63d0\u4f9b\u7ed9\u7528\u6237\u8bbf\u95ee\u3002<\/p>\n<p>\u4e8c\u3001\u6b65\u9aa4<\/p>\n<p>1. \u51c6\u5907\u5de5\u4f5c<\/p>\n<p>\u5728\u5f00\u59cb\u6253\u5305\u524d\uff0c\u9700\u8981\u5148\u5b89\u88c5 Node.js \u548c npm\u3002\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\u4e86\uff0c\u8bf7\u8df3\u8fc7\u6b64\u6b65\u9aa4\u3002<\/p>\n<p>2. \u521b\u5efa\u9879\u76ee<\/p>\n<p>\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\uff0c\u5e76\u8fdb\u5165\u9879\u76ee\u76ee\u5f55\u3002<\/p>\n<p>&#8220;`<\/p>\n<p>mkdir my-app<\/p>\n<p>cd my-app<\/p>\n<p>&#8220;`<\/p>\n<p>3. \u521d\u59cb\u5316\u9879\u76ee<\/p>\n<p>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u4f7f\u7528 npm \u521d\u59cb\u5316\u9879\u76ee\u3002<\/p>\n<p>&#8220;`<\/p>\n<p>npm init<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u5c06\u4f1a\u521b\u5efa\u4e00\u4e2a package.json \u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u9879\u76ee\u7684\u57fa\u672c\u4fe1\u606f\u548c\u4f9d\u8d56\u9879\u3002<\/p>\n<p>4. \u5b89\u88c5\u4f9d\u8d56<\/p>\n<p>\u5c06\u9700\u8981\u7684\u4f9d\u8d56\u9879\u5b89\u88c5\u5230\u9879\u76ee\u4e2d\u3002<\/p>\n<p>&#8220;`<\/p>\n<p>npm install &#8211;save express<\/p>\n<p>npm install &#8211;save-dev concurrently<\/p>\n<p>npm install &#8211;save-dev electron<\/p>\n<p>npm install &#8211;save-dev wait-on<\/p>\n<p>&#8220;`<\/p>\n<p>\u5176\u4e2d\uff0cexpress \u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684 Web \u670d\u52a1\u5668\uff0cconcurrently \u53ef\u4ee5\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u547d\u4ee4\uff0celectron \u662f\u7528\u4e8e\u521b\u5efa\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u6846\u67b6\uff0cwait-on \u53ef\u4ee5\u7b49\u5f85\u67d0\u4e2a URL \u53ef\u8bbf\u95ee\u540e\u518d\u6267\u884c\u4e0b\u4e00\u6b65\u64cd\u4f5c\u3002<\/p>\n<p>5. \u521b\u5efa\u4e3b\u8fdb\u7a0b\u6587\u4ef6<\/p>\n<p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a main.js \u7684\u6587\u4ef6\uff0c\u4f5c\u4e3a Electron \u7684\u4e3b\u8fdb\u7a0b\u3002<\/p>\n<p>&#8220;`<\/p>\n<p>const { app, BrowserWindow } = require(&#8216;electron&#8217;)<\/p>\n<p>const path = require(&#8216;path&#8217;)<\/p>\n<p>const url = require(&#8216;url&#8217;)<\/p>\n<p>let win<\/p>\n<p>function createWindow () {<\/p>\n<p>  win = new BrowserWindow({ width: 800, height: 600 })<\/p>\n<p>  win.load<a href=\"https:\/\/exe.yimenapp.com\/tool-369.html\">\u7f51\u5740\u6253\u5305\u6210exe\u8f6f\u4ef6<\/a>URL(url.format({<\/p>\n<p>    pathname: path.join(__dirname, &#8216;index.html&#8217;),<\/p>\n<p>    protocol: &#8216;file:&#8217;,<\/p>\n<p>    slashes: true<\/p>\n<p>  }))<\/p>\n<p>  win.on(&#8216;closed&#8217;, () =&gt; {<\/p>\n<p>    win = null<\/p>\n<p>  })<\/p>\n<p>}<\/p>\n<p>app.on(&#8216;ready&#8217;, 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 (win === null) {<\/p>\n<p>    createWindow()<\/p>\n<p>  }<\/p>\n<p>})<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a Electron \u7a97\u53e3\uff0c\u5e76\u52a0\u8f7d\u4e86 index.html \u6587\u4ef6\u3002<\/p>\n<p>6. \u521b\u5efa\u6e32\u67d3\u8fdb\u7a0b\u6587\u4ef6<\/p>\n<p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a index.html \u7684\u6587\u4ef6\uff0c\u4f5c\u4e3a Electron \u7684\u6e32\u67d3\u8fdb\u7a0b\u3002<\/p>\n<p>&#8220;`<\/p>\n<\/p>\n<p>\n<p>\n<p>  <title>My App<\/title><\/p>\n<\/p>\n<p>\n<p>  Hello World!<\/p>\n<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684 HTML \u6587\u4ef6\uff0c\u7528\u4e8e\u663e\u793a &#8220;Hello World!&#8221;\u3002<\/p>\n<p>7. \u521b\u5efa\u542f\u52a8\u811a\u672c<\/p>\n<p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a start.js \u7684\u6587\u4ef6\uff0c\u7528\u4e8e\u542f\u52a8 Web \u670d\u52a1\u5668\u548c Electron\u3002<\/p>\n<p>&#8220;`<\/p>\n<p>const express = require(&#8216;express&#8217;)<\/p>\n<p>const path = requir<a href=\"https:\/\/exe.yimenapp.com\/tool-3514.html\">\u81ea\u5236\u8f6f\u4ef6\u6253\u5305exe<\/a>e(&#8216;path&#8217;)<\/p>\n<p>const waitOn = require(&#8216;wait-on&#8217;)<\/p>\n<p>const { spawn } = require(&#8216;child_process&#8217;)<\/p>\n<p>const app = express()<\/p>\n<p>app.use(express.static(path.join(__dirname, &#8216;public&#8217;)))<\/p>\n<p>app.get(&#8216;\/&#8217;, (req, res) =&gt; {<\/p>\n<p>  res.sendFile(path.join(__dirname, &#8216;index.html&#8217;))<\/p>\n<p>})<\/p>\n<p>const server = app.listen(3000, () =&gt; {<\/p>\n<p>  console.log(&#8216;Web server started on port 3000&#8217;)<\/p>\n<p>})<\/p>\n<p>waitOn({<\/p>\n<p>  resources: [&#8216;http:\/\/localhost:3000&#8217;],<\/p>\n<p>  timeout: 30000<\/p>\n<p>}).then(() =&gt; {<\/p>\n<p>  console.log(&#8216;Web server is ready&#8217;)<\/p>\n<p>  const electron = spawn(&#8216;electron&#8217;, [&#8216;.&#8217;])<\/p>\n<p>  electron.stdout.on(&#8216;data&#8217;, (data) =&gt; {<\/p>\n<p>    console.log(`Electron stdout: ${data}`)<\/p>\n<p>  })<\/p>\n<p>  electron.stderr.on(&#8216;data&#8217;, (data) =&gt; {<\/p>\n<p>    console.error(`Electron stderr: ${data}`)<\/p>\n<p>  })<\/p>\n<p>  elec<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.yimenyun.net\/2023-03\/24\/12\/27017830551.jpg\" \/><\/figure>\n<\/p>\n<p>tron.on(&#8216;close&#8217;, (code) =&gt; {<\/p>\n<p>    console.log(`Electron exited with code ${code}`)<\/p>\n<p>    server.close()<\/p>\n<p>  })<\/p>\n<p>}).catch((err) =&gt; {<\/p>\n<p>  console.error(`Web server failed to start: ${err}`)<\/p>\n<p>  server.close()<\/p>\n<p>})<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a Web \u670d\u52a1\u5668\uff0c\u5e76\u542f\u52a8\u4e86 Electron\u3002\u5176\u4e2d\uff0c\u4f7f\u7528 waitOn \u7b49\u5f85 Web \u670d\u52a1\u5668\u542f\u52a8\u5b8c\u6210\u540e\u518d\u542f\u52a8 Electron\u3002<\/p>\n<p>8. \u6253\u5305\u5e94\u7528<\/p>\n<p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a package.json \u7684\u6587\u4ef6\uff0c\u7528\u4e8e\u6253\u5305\u5e94\u7528\u3002<\/p>\n<p>&#8220;`<\/p>\n<p>{<\/p>\n<p>  &#8220;name&#8221;: &#8220;my-app&#8221;,<\/p>\n<p>  &#8220;version&#8221;: &#8220;1.0.0&#8221;,<\/p>\n<p>  &#8220;description&#8221;: &#8220;My App&#8221;,<\/p>\n<p>  &#8220;main&#8221;: &#8220;start.js&#8221;,<\/p>\n<p>  &#8220;scripts&#8221;: {<\/p>\n<p>    &#8220;start&#8221;: &#8220;concurrently \\&#8221;npm run start-web\\&#8221; \\&#8221;npm run start-electron\\&#8221;&#8221;,<\/p>\n<p>    &#8220;start-web&#8221;: &#8220;node start.js&#8221;,<\/p>\n<p>    &#8220;start-electron&#8221;: &#8220;electron .&#8221;,<\/p>\n<p>    &#8220;package&#8221;: &#8220;electron-packager . my-app &#8211;platform=win32 &#8211;arch=x64 &#8211;out=dist &#8211;overwrite&#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;dependencies&#8221;: {<\/p>\n<p>    &#8220;express&#8221;: &#8220;^4.17.1&#8221;<\/p>\n<p>  },<\/p>\n<p>  &#8220;devDependencies&#8221;: {<\/p>\n<p>    &#8220;concurrently&#8221;: &#8220;^5.3.0&#8221;,<\/p>\n<p>    &#8220;electron&#8221;: &#8220;^11.0.0&#8221;,<\/p>\n<p>    &#8220;wait-on&#8221;: &#8220;^5.2.1&#8221;<\/p>\n<p>  }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u5176\u4e2d\uff0cscripts \u4e2d\u5b9a\u4e49\u4e86\u542f\u52a8 Web \u670d\u52a1\u5668\u548c Electron \u7684\u547d\u4ee4\uff0c\u4ee5\u53ca\u6253\u5305\u5e94\u7528\u7684\u547d\u4ee4\u3002\u4f7f\u7528 electron-packager \u6253\u5305\u5e94\u7528\uff0c\u5c06\u524d\u7aef\u5e94\u7528\u548c Electron \u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p>9. \u6253\u5305\u5e94\u7528<\/p>\n<p>\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c\u6253\u5305\u547d\u4ee4\u3002<\/p>\n<p>&#8220;`<\/p>\n<p>npm run package<\/p>\n<p>&#8220;`<\/p>\n<p>\u6253\u5305\u5b8c\u6210\u540e\uff0c\u5728 dist \u76ee\u5f55\u4e0b\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3a my-app-win32-x64 \u7684\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u53ef\u6267\u884c\u6587\u4ef6\u548c\u76f8\u5173\u8d44\u6e90\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u7aef\u5e94\u7528\u6253\u5305\u6210\u53ef\u6267\u884c\u7a0b\u5e8f\uff08exe\uff09\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728 Windows \u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u5206\u53d1\u548c\u5b89\u88c5\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u524d\u7aef\u5e94\u7528\u6253\u5305\u6210 exe \u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002\u4e00\u3001\u539f\u7406\u524d\u7aef\u5e94\u7528\u6253\u5305\u6210 exe \u7684<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[927,34533,429,132,728],"topic":[],"class_list":["post-38183","post","type-post","status-publish","format-standard","hentry","category-kaifaexe","tag-appexe","tag-deb","tag-429","tag-132","tag-728"],"_links":{"self":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/38183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/comments?post=38183"}],"version-history":[{"count":1,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/38183\/revisions"}],"predecessor-version":[{"id":38199,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/38183\/revisions\/38199"}],"wp:attachment":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/media?parent=38183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/categories?post=38183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/tags?post=38183"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/topic?post=38183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}