{"id":2233,"date":"2023-08-07T15:47:48","date_gmt":"2023-08-07T07:47:48","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=2233"},"modified":"2023-08-07T15:47:48","modified_gmt":"2023-08-07T07:47:48","slug":"html5%e7%94%9f%e6%88%90exe%e6%98%af%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e7%9a%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/2233\/","title":{"rendered":"html5\u751f\u6210exe\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1f"},"content":{"rendered":"

HTML5\u662f\u4e00\u79cd\u7528\u4e8e\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u6807\u51c6\uff0c\u5b83\u53ef\u4ee5\u5728\u591a\u79cd\u8bbe\u5907\u4e0a\u8fd0\u884c\uff0c\u5305\u62ec\u684c\u9762\u7535\u8111\u3001\u79fb\u52a8\u8bbe\u5907\u548c\u667a\u80fd\u7535\u89c6\u7b49\u3002HTML5\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u4f5c\u4e3aWeb\u5e94\u7528\u7a0b\u5e8f\u6216\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\uff0c\u800c\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u6bd4Web\u5e94\u7528\u7a0b\u5e8f\u66f4\u52a0\u5feb\u901f\u3001\u7a33\u5b9a\u548c\u5b89\u5168\u3002\u56e0\u6b64\uff0c\u6709\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\uff0c\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Electron\u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

Electron\u662f\u4e00\u5c01\u88c5\u7f51\u7ad9<\/a>\u4e2a\u5f00\u6e90\u6846\u67b6\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u4f7f\u7528HTML\u3001CSS\u548cJavaScript\u6784\u5efa\u8de8\u5e73\u53f0\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002Electron\u4f7f\u7528Chromium\u548cNode.js\u4f5c\u4e3a\u5b83\u7684\u5e95\u5c42\u6280\u672f\uff0c\u56e0\u6b64\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u73b0\u6709\u7684Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u3002Electron\u652f\u6301Windows\u3001macOS\u548cLinux\u7b49\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\uff0c\u56e0\u6b64\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u6784\u5efa\u8de8\u5e73\u53f0\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u4e0b\u9762\u662f\u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u8f6cweb\u6253\u5305exe\u6587\u4ef6\u5bfc\u51fa<\/a>\u6362\u4e3a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u7684\u6b65\u9aa4\uff1a<\/p>\n

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

\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5Electron\u3002\u53ef\u4ee5\u4f7f\u7528npm\uff08Node.js\u5305\u7ba1\u7406\u5668\uff09\u6765\u5b89\u88c5Electron\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

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

\u5728\u5b89\u88c5Electron\u540e\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\u3002\u53ef\u4ee5\u4f7f\u7528Electron\u63d0\u4f9b\u7684\u811a\u624b\u67b6\u5de5\u5177\u6765\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

npx electron-forge init my-app<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cmy-app\u201d\u7684Electron\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

3. \u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0\u5230Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d<\/p>\n

\u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0\u5230Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\u9700\u8981\u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u7684\u6587\u4ef6\u590d\u5236\u5230Electron\u5e94\u7528\u7a0b\u5e8f\u7684\u6587\u4ef6\u5939\u4e2d\u3002\u53ef\u4ee5\u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u7684\u6587\u4ef6\u590d\u5236\u5230Electron\u5e94\u7528\u7a0b\u5e8f\u7684\u201capp\u201d\u6587\u4ef6\u5939\u4e2d\u3002\u5728\u201capp\u201d\u6587\u4ef6\u5939\u4e2d\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cindex.html\u201d\u7684\u6587\u4ef6\uff0c\u8fd9\u662fHTML5\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u6587\u4ef6\u3002<\/p>\n

4. \u914d\u7f6eElectron\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u9700\u8981\u914d\u7f6eElectron\u5e94\u7528\u7a0b\u5e8f\uff0c\u4ee5\u4fbf\u5b83\u53ef\u4ee5\u8fd0\u884cHTML5\u5e94\u7528\u7a0b\u5e8f\u3002\u53ef\u4ee5\u5728Electron\u5e94\u7528\u7a0b\u5e8f\u7684\u201cmain.js\u201d\u6587\u4ef6\u4e2d\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u201cmain.js\u201d\u6587\u4ef6\u793a\u4f8b\uff1a<\/p>\n

“`<\/p>\n

const { 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.<\/p>\n

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

whenReady().then(() => {<\/p>\n

createWindow()<\/p>\n

app.on(‘activate’, () => {<\/p>\n

if (BrowserWindow.getAllWindows().length === 0) {<\/p>\n

createWindow()<\/p>\n

}<\/p>\n

})<\/p>\n

})<\/p>\n

app.on(‘window-all-closed’, () => {<\/p>\n

if (process.platform !== ‘darwin’) {<\/p>\n

app.quit()<\/p>\n

}<\/p>\n

})<\/p>\n

“`<\/p>\n

\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a\u201ccreateWindow\u201d\u7684\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u6d4f\u89c8\u5668\u7a97\u53e3\uff0c\u5e76\u52a0\u8f7d\u4e86\u201cindex.html\u201d\u6587\u4ef6\u3002\u5728\u201capp.whenReady()\u201d\u51fd\u6570\u4e2d\uff0c\u8c03\u7528\u4e86\u201ccreateWindow\u201d\u51fd\u6570\u6765\u521b\u5efa\u4e00\u4e2a\u6d4f\u89c8\u5668\u7a97\u53e3\u3002\u5728\u201capp.on(‘activate’)\u201d\u51fd\u6570\u4e2d\uff0c\u5f53\u6240\u6709\u7a97\u53e3\u90fd\u5173\u95ed\u65f6\uff0c\u518d\u6b21\u8c03\u7528\u201ccreateWindow\u201d\u51fd\u6570\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6d4f\u89c8\u5668\u7a97\u53e3\u3002<\/p>\n

5. \u6253\u5305Electron\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u6700\u540e\uff0c\u9700\u8981\u5c06Electron\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528Electron\u63d0\u4f9b\u7684\u6253\u5305\u5de5\u5177\u6765\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

npx electron-forge make<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u5728Windows\u3001macOS\u548cLinux\u4e0a\u8fd0\u884c\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

\u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u4f7f\u7528Electron\u6846\u67b6\u3002\u4f7f\u7528Electron\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u73b0\u6709\u7684Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5728\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u3002Electron\u63d0\u4f9b\u4e86\u8bb8\u591a\u5de5\u5177\u548cAPI\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u6784\u5efa\u8de8\u5e73\u53f0\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

HTML5\u662f\u4e00\u79cd\u7528\u4e8e\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u6807\u51c6\uff0c\u5b83\u53ef\u4ee5\u5728\u591a\u79cd\u8bbe\u5907\u4e0a\u8fd0\u884c\uff0c\u5305\u62ec\u684c\u9762\u7535\u8111\u3001\u79fb\u52a8\u8bbe\u5907\u548c\u667a\u80fd\u7535\u89c6\u7b49\u3002HTML5\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u4f5c\u4e3aWeb\u5e94\u7528\u7a0b\u5e8f\u6216\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\uff0c\u800c\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u6bd4Web\u5e94\u7528\u7a0b\u5e8f\u66f4<\/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":[4710,4711,12,16,300],"topic":[],"class_list":["post-2233","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-window","tag-exe","tag-12","tag-16","tag-300"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2233","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=2233"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2233\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=2233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=2233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=2233"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=2233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}