{"id":1779,"date":"2023-08-03T15:48:08","date_gmt":"2023-08-03T07:48:08","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=1779"},"modified":"2023-08-03T15:48:08","modified_gmt":"2023-08-03T07:48:08","slug":"h5%e6%89%93%e5%8c%85exe%e7%a8%8b%e5%ba%8f%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\/1779\/","title":{"rendered":"h5\u6253\u5305exe\u7a0b\u5e8f\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1f"},"content":{"rendered":"

HTML5 (H5) \u662f\u4e00\u79cd\u57fa\u4e8eWeb\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\uff0c\u4f46\u662f\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u683c\u5f0f\uff0c\u4ee5\u4fbf\u5728\u4e0d\u9700\u8981\u6d4f\u89c8\u5668\u7684\u60c5\u51b5\u4e0b\u8fd0\u884c\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210.exe\u6587\u4ef6\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n

## \u6253\u5305\u539f\u7406<\/p>\n

\u6253\u5305H5\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u4f7f\u7528Electron\u6846\u67b6\u3002Electron\u6846\u67b6\u662f\u4e00\u4e2a\u57fa\u4e8eNode.js\u548cChromium\u7684\u5f00\u6e90\u6846\u67b6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5feb\u901f\u521b\u5efa\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002Electron\u4f7f\u7528HTML\u3001CSS\u548cJavaScript\u7b49Web\u6280\u672f\u6765\u521b\u5efa\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Electron\u6765\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

Electron\u6846\u67b6\u4e2d\u6709\u4e24\u4e2a\u4e3b\u8981\u7684\u8fdb\u7a0b\uff1a\u4e3b\u8fdb\u7a0b\u548c\u6e32\u67d3\u8fdb\u7a0b\u3002\u4e3b\u8fdb\u7a0b\u662f\u4e00\u4e2aNode.js\u8fdb\u7a0b\uff0c\u8d1f\u8d23\u7ba1\u7406\u5e94\u7528\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\u3001\u521b\u5efa\u7a97\u53e3\u548c\u5904\u7406\u7cfb\u7edf\u4e8b\u4ef6\u7b49\u3002\u6e32\u67d3\u8fdb\u7a0b\u662f\u4e00\u4e2aChromium\u8fdb\u7a0b\uff0c\u8d1f\u8d23\u6e32\u67d3\u5e94\u7528\u7a0b\u5e8f\u7684UI\u754c\u9762\u3002<\/p>\n

\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u57fa\u672c\u539f\u7406\u662f\u5c06H5\u5e94\u7528\u7a0b\u5e8f<\/p>\n

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

\u4f5c\u4e3a\u4e00\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\uff0c\u7136\u540e\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u7684\u4ee3\u7801\u548c\u8d44\u6e90\u6587\u4ef6\u5d4c\u5165\u5230Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u6700\u540e\u5c06Electron\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

## \u6253\u5305\u6b65\u9aa4<\/p>\n

\u4e0b\u9762\u662f\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n

### \u6b65\u9aa41\uff1a\u521b\u5efaElectron\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528Node.js\u548cnpm\u5b89\u88c5Electron\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

\u7136\u540e\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amain.js\u7684\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

“`javascript<\/p>\n

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

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

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

width: 800,<\/p>\n

hue5windows\u6253\u5305<\/a>eight: 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(() => {<\/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

\u8fd9\u4e2a\u6587\u4ef6\u521b\u5efa\u4e86\u4e00\u4e2aElectron\u7a97\u53e3\u5e76\u52a0\u8f7d\u4e86\u4e00\u4e2a\u540d\u4e3aindex.html\u7684\u6587\u4ef6\u3002<\/p>\n

### \u6b65\u9aa42\uff1a\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7801\u548c\u8d44\u6e90\u6587\u4ef6\u5d4c\u5165\u5230Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7801\u548c\u8d44\u6e90\u6587\u4ef6\u5d4c\u5165\u5230Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002\u6211\u4eec\u53ef\u4ee5\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u7684\u4ee3\u7801\u548c\u8d44\u6e90\u6587\u4ef6\u653e\u5728Electron\u5e94\u7528\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\u4e0b\u7684\u4e00\u4e2a\u540d\u4e3aapp\u7684\u5b50\u76ee\u5f55\u4e2d\u3002\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728main.js\u6587\u4ef6\u4e2d\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5c06app\u76ee\u5f55\u52a0\u8f7d\u5230Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff1a<\/p>\n

“`javascript<\/p>\n

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

“`<\/p>\n

### \u6b65\u9aa43\uff1a\u6253\u5305Electron\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u5c06Electron\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Electron Builder\u5de5\u5177\u6765\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

\u7136\u5c06html\u6587\u4ef6\u8f6c\u6210\u684c\u9762exe\u7a0b\u5e8f<\/a>\u540e\uff0c\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aelectron-builder.yml\u7684\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

“`yaml<\/p>\n

appId: com.example.myapp<\/p>\n

productName: My App<\/p>\n

directories:<\/p>\n

output: dist<\/p>\n

files:<\/p>\n

– name: app<\/p>\n

target: app<\/p>\n

– name: node_modules<\/p>\n

target: node_modules<\/p>\n

– name: main.js<\/p>\n

target: .<\/p>\n

– name: package.json<\/p>\n

target: .<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u6587\u4ef6\u6307\u5b9a\u4e86\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\u3001\u8f93\u51fa\u76ee\u5f55\u548c\u8981\u6253\u5305\u7684\u6587\u4ef6\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n

“`<\/p>\n

npx electron-builder build<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u5c06\u4f1a\u5728dist\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

## \u603b\u7ed3<\/p>\n

\u672c\u6587\u4ecb\u7ecd\u4e86\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

HTML5 (H5) \u662f\u4e00\u79cd\u57fa\u4e8eWeb\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\uff0c\u4f46\u662f\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5c06H5\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u683c\u5f0f\uff0c\u4ee5\u4fbf\u5728\u4e0d\u9700\u8981\u6d4f\u89c8\u5668\u7684\u60c5\u51b5\u4e0b\u8fd0\u884c\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5c06H5\u5e94<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[3813,3814,256,12,16],"topic":[],"class_list":["post-1779","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-macos","tag-window","tag-256","tag-12","tag-16"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/1779","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\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=1779"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/1779\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=1779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=1779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=1779"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=1779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}