{"id":17361,"date":"2024-03-04T15:43:00","date_gmt":"2024-03-04T07:43:00","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/17361\/"},"modified":"2024-03-04T15:43:00","modified_gmt":"2024-03-04T07:43:00","slug":"web%e6%89%93%e5%8c%85exe%e6%a1%86%e6%9e%b6%e6%9c%89%e5%93%aa%e4%ba%9b%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/17361\/","title":{"rendered":"web\u6253\u5305exe\u6846\u67b6\u6709\u54ea\u4e9b\uff1f"},"content":{"rendered":"

Web\u6253\u5305EXE\u6846\u67b6\u662f\u4e00\u79cd\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u6280\u672f\u3002\u5b83\u7684\u539f\u7406\u662f\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u7684\u6587\u4ef6\u548c\u8d44\u6e90\u6253\u5305\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7528\u6237\u53ea\u9700\u8981\u4e0b\u8f7d\u4e00\u4e2aexe\u6587\u4ef6\uff0c\u5c31\u53ef\u4ee5\u8fd0\u884c\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u65e0\u9700\u5b89\u88c5\u4efb\u4f55\u5176\u4ed6\u8f6f\u4ef6\u3002\u8fd9\u79cd\u6280\u672f\u53ef\u4ee5\u65b9\u4fbf\u7528\u6237\u4f7f\u7528Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u4e5f\u53ef\u4ee5\u4fdd\u62a4Web\u5e94\u7528\u7a0b\u5e8f\u7684\u4ee3\u7801\u548c\u8d44\u6e90\uff0c\u9632\u6b62\u88ab\u76d7\u7528\u3002<\/p>\n

Web\u6253\u5305EXE\u6846\u67b6\u7684\u5b9e\u73b0\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e0b\u9762\u5c06\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u57fa\u4e8eElectron\u6846\u67b6\u7684\u5b9e\u73b0\u65b9\u5f0f\u3002<\/p>\n

Electron\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u6846\u67b6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u4f7f\u7528Web\u6280\u672f\uff08HTML\u3001CSS\u3001JavaScript\uff09\u6784\u5efa\u8de8\u5e73\u53f0\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u57fa\u4e8eChromium\u548cNode.js\uff0c\u53ef\u4ee5\u8ba9\u5f00\u53d1\u8005\u4f7f\u7528Web\u6280\u672f\u5f00\u53d1\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u540c\u65f6\u5177\u5907\u539f\u751f\u5e94\u7528\u7a0b\u5e8f\u7684\u7279\u6027\uff0c\u5982\u8bbf\u95ee\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u3001\u64cd\u4f5c\u7cfb\u7edfAPI\u7b49\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u4f7f\u7528Electron\u6846\u67b6\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u4e0b\u9762\u662f\u4e00\u4e2a\u57fa\u4e8eElectron\u6846\u67b6\u5b9e\u73b0Web\u6253\u5305EXE\u7684\u7b80\u5355\u6d41\u7a0b\uff1a<\/p>\n

1. \u5b89\u88c5Electron\u6846\u67b6<\/p>\n

\u9996\u5148\u9700\u8981\u5b89\u88c5Electron\u6846\u67b6\uff0c\u53ef\u4ee5\u4f7f\u7528npm\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n

“`<\/p>\n

npm install electron –save-dev<\/p>\n

“`<\/p>\n

2. \u521b\u5efaElectron\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u4f7f\u7528Electron\u63d0\u4f9b\u7684API\u521b\u5efa\u4e00\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u52a0\u8f7dWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u6587\u4ef6\uff08\u5982index.html\uff09\uff0c\u5e76\u8bbe\u7f6e\u7a97\u53e3\u7684\u5927\u5c0f\u3001\u56fe\u6807\u7b49\u5c5e\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684Electron\u5e94\u7528\u7a0b\u5e8f\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n

“`javascript<\/p>\n

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

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

\/\/ \u521b\u5efa\u6d4f\u89c8\u5668\u7a97web\u8f6c\u6210exe<\/a>\u53e3<\/p>\n

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

width: 800,<\/p>\n

height: 600,<\/p>\n

icon: ‘icon.png’,<\/p>\n

webPreferences: {<\/p>\n

nodeIntegration: true \/\/ \u5728\u6e32\u67d3\u8fdb\u7a0b\u4e2d\u4f7f\u7528Node.js<\/p>\n

}<\/p>\n

})<\/p>\n

\/\/ \u52a0\u8f7dWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u6587\u4ef6<\/p>\n

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

}<\/p>\n

\/\/ \u5f53Electron\u521d\u59cb\u5316\u5b8c\u6210\u5e76\u51c6\u5907\u597d\u521b\u5efa\u6d4f\u89c8\u5668\u7a97\u53e3\u65f6\u8c03\u7528<\/p>\n

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

“`<\/p>\n

3. \u6253\u5305Web\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u4f7f\u7528Electron\u63d0\u4f9b\u7684\u6253\u5305\u5de5\u5177electron-packager\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u9700\u8981\u6307\u5b9a\u8981\u6253\u5305\u7684\u5e94\u7528\u7a0b\u5e8f\u8def\u5f84\u3001\u5e73\u53f0\u3001\u67b6\u6784\u3001\u8f93\u51fa\u76ee\u5f55\u7b49\u53c2\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6253\u5305\u547d\u4ee4\u7684\u793a\u4f8b\uff1a<\/p>\n

“`<\/p>\n

electron-packager . myApp –p<\/p>\n

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

latform=win32 –arch=x64 –out=out<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c.\u8868\u793a\u5f53\u524d\u76ee\u5f55\uff0cmyApp\u8868\u793a\u6253\u5305\u540e\u7684\u5e94\u7528\u7a0b\u5e8f\u540d\u79f0\uff0c–platform\u8868\u793a\u8981\u6253\u5305\u7684\u5e73\u53f0\uff08\u5982Windows\u3001macOS\u3001Linux\u7b49\uff09\uff0c–arch\u8868\u793a\u8981\u6253\u5305\u7684\u67b6\u6784\uff08\u5982x64\u3001ia32\u7b49\uff09\uff0c–out\u8868\u793a\u6253\u5305\u7684\u8f93\u51fa\u76ee\u5f55\u3002<\/p>\n

4. \u8fd0\u884c\u6253\u5305\u540e\u7684\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u6253\u5305\u540e\u7684\u5e94\u7528\u7a0b\u5e8f\u4f4d\u4e8e\u8f93\u51fa\u76ee\u5f55\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u5b83\u3002\u8fd0\u884c\u540e\uff0c\u5e94\u7528\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u52a0\u8f7dWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u6587\u4ef6\uff0c\u5e76\u5728Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8fd0\u884c\u3002<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u56db\u4e2a\u6b65\u9aa4\uff0c\u5c31\u53ef\u4ee5\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u65b9\u4fbf\u7528\u6237\u4f7f\u7528\u3002\u540c\u65f6\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528Electron\u63d0\u4f9b\u7684\u5176\u4ed6\u7279\u6027\uff0c\u5982\u6253\u5305\u6210\u8de8\u5e73\u53f0\u7684\u5e94\u7528\u7a0b\u5e8f\u3001\u4f7f\u7528\u539f\u751fAPI\u7b49\u3002<\/p>\n

\u603b\u4e4b\uff0cWeb\u6253\u5305EXE\u6846\u67b6\u53ef\u4ee5\u5e2e\u52a9Web\u5f00\u53d1\u8005\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u65b9\u4fbf\u7528\u6237\u4f7f\u7528\u548c\u4fdd\u62a4\u4ee3\u7801\u8d44\u6e90\u3002\u57fa\u4e8eElectron\u6846\u67b6\u7684\u5b9e\u73b0\u65b9\u5f0f\u53ef\u4ee5\u8ba9\u5f00\u53d1\u8005\u4f7f\u7528\u719f\u6089\u7684Web\u6280\u672fultraisolinux<\/a>\u5f00\u53d1\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u540c\u65f6\u5177\u5907\u539f\u751f\u5e94\u7528\u7a0b\u5e8f\u7684\u7279\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Web\u6253\u5305EXE\u6846\u67b6\u662f\u4e00\u79cd\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u6280\u672f\u3002\u5b83\u7684\u539f\u7406\u662f\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u7684\u6587\u4ef6\u548c\u8d44\u6e90\u6253\u5305\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7528\u6237\u53ea\u9700\u8981\u4e0b\u8f7d\u4e00\u4e2aexe\u6587\u4ef6\uff0c\u5c31\u53ef\u4ee5\u8fd0\u884c\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u65e0\u9700\u5b89\u88c5\u4efb\u4f55<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[12,8970,25,384,20322],"topic":[],"class_list":["post-17361","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-12","tag-exe","tag-25","tag-384","tag-20322"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/17361","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\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=17361"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/17361\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=17361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=17361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=17361"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=17361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}