{"id":17166,"date":"2024-03-03T15:43:05","date_gmt":"2024-03-03T07:43:05","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=17166"},"modified":"2024-03-03T15:43:05","modified_gmt":"2024-03-03T07:43:05","slug":"web%e5%8f%af%e4%bb%a5%e6%89%93%e5%8c%85exe%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/17166\/","title":{"rendered":"web\u53ef\u4ee5\u6253\u5305exe\u5417\uff1f"},"content":{"rendered":"

Web\u5e94\u7528\u7a0b\u5e8f\u662f\u4e00\u79cd\u57fa\u4e8e\u4e92\u8054\u7f51\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u4eec\u8fd0\u884c\u5728Web\u670d\u52a1\u5668\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7Web\u6d4f\u89c8\u5668\u6765\u8bbf\u95ee\u3002\u4e0e\u4f20\u7edf\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u4e0d\u540c\uff0cWeb\u5e94\u7528\u7a0b\u5e8f\u4e0d\u9700\u8981\u5b89\u88c5\u548c\u4e0b\u8f7d\uff0c\u7528\u6237\u53ea\u9700\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u5373\u53ef\u3002\u7136\u800c\uff0c\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4ee5\u4fbf\u4e8e\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\u8fd0\u884c\u6216\u8005\u66f4\u597d\u5730\u4fdd\u62a4\u5e94\u7528\u7a0b\u5e8f\u7684\u5b89\u5168\u6027\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u4e00\u3001\u6253\u5305\u65b9\u5f0f<\/p>\n

\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u6709\u591a\u79cd\u65b9\u5f0f\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u65b9\u5f0f\u662f\u4f7f\u7528Electron\u548cNW.js\u3002\u8fd9\u4e24\u79cd\u5de5\u5177\u90fd\u662f\u57fa\u4e8eNode.js\u5f00\u53d1\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\uff0c\u53ef\u4ee5\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u6b64\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u5de5\u5177\uff0c\u5982AppJS\u548cDeskGap\u7b49\uff0c\u4e5f\u53ef\u4ee5\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u4e8c\u3001Electron<\/p>\n

Electron\u662f\u7531GitHub\u5f00\u53d1\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u652f\u6301Windows\u3001macOS\u548cLinux\u7b49\u591a\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u3002Electron\u4f7f\u7528Chromium\u4f5c\u4e3a\u6e32\u67d3\u5f15\u64ce\uff0c\u53ef\u4ee5\u8fd0\u884cHTML\u3001CSS\u548cJavaScript\u7b49Web\u6280\u672f\u3002\u5728Electron\u4e2d\uff0cWeb\u5e94\u7528\u7a0b\u5e8f\u88ab\u5c01\u88c5\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u901a\u8fc7\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u548c\u64cd\u4f5c\u7cfb\u7edfAPI\u8bbf\u95ee\u672c\u5730\u8d44\u6e90\u548c\u529f\u80fd\u3002<\/p>\n

Electron\u7684\u6253\u5305\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n

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

\u9996\u5148\u9700\u8981\u5b89\u88c5Electron\uff0c\u53ef\u4ee5\u901a\u8fc7npm\u5b89\u88c5\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

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

\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amain.js\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n

“`javascript<\/p>\n

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

const path = require(‘path’)<\/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.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

\n

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

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

}<\/p>\n

})<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u6587\u4ef6\u662fElectron\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u6587\u4ef6\uff0c\u5b83\u521b\u5efa\u4e86\u4e00\u4e2a\u7a97\u53e3\u5e76\u52a0\u8f7dindex.html\u6587\u4ef6\u3002<\/p>\n

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

\u4f7f\u7528Electron-builder\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2abuild\u6587\u4ef6\u5939\uff0c\u5e76\u5728\u5176\u4e2d\u521b\u5efa\u4e00\u4e2aelectron-builder.yaml\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n

“`yaml<\/p>\n

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

pro\u524d\u7aef\u9875\u9762\u751f\u6210exe<\/a>ductName: MyApp<\/p>\n

directories:<\/p>\n

output: dist<\/p>\n

mac:<\/p>\n

category: your.app.category.type<\/p>\n

target: dmg<\/p>\n

win:<\/p>\n

target: nsis<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0cappId\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u552f\u4e00\u6807\u8bc6\u7b26\uff0cproductName\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\uff0cdirectories.output\u662f\u6253\u5305\u8f93\u51fa\u7684\u76ee\u5f55\uff0cmac\u548cwin\u5206\u522b\u662fmacOS\u548cWindows\u7684\u6253\u5305\u914d\u7f6e\u3002<\/p>\n

\u7136\u540e\uff0c\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

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

\u4e09\u3001NW.js<\/p>\n

NW.js\u662f\u53e6\u4e00\u4e2a\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u5b83\u4e5f\u662f\u57fa\u4e8eNode.js\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\u3002\u4e0eElectron\u4e0d\u540c\u7684\u662f\uff0cNW.js\u4f7f\u7528\u4e86Node.js\u7684\u539f\u751f\u6a21\u5757\uff0c\u53ef\u4ee5\u5728Web\u5e94\u7528\u7a0b\u5e8f\u4e2d\u76f4\u63a5\u4f7f\u7528Node.js\u7684API\u3002<\/p>\n

NW.js\u7684\u6253\u5305\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n

1. \u5b89\u88c5NW.js<\/p>\n

\u9996\u5148\u9700\u8981\u5b89\u88c5NW.js\uff0c\u53ef\u4ee5\u901a\u8fc7npm\u5b89\u88c5\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

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

\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3apackage.json\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n

“`json<\/p>\n

{<\/p>\n

“name”: “my-app”,<\/p>\n

“main”: “index.html”,<\/p>\n

“window”: {<\/p>\n

“width”: 800,<\/p>\n

“height”: 600<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u6587\u4ef6\u662fNW.js\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5176\u4e2dname\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\uff0cmain\u662f\u5165\u53e3\u6587\u4ef6\uff0cwindow\u662f\u7a97\u53e3\u7684\u5927\u5c0f\u3002<\/p>\n

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

\u4f7f\u7528nw-builder\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

npx nw-builder . -o build -p win64<\/p>\n

“`<\/p>\n

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

\u56db\u3001\u603b\u7ed3<\/p>\n

\u901a\u8fc7\u4f7f\u7528Electron\u6216NW.js\u7b49\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\uff0c\u53ef\u4ee5\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4f7f\u5e94\u7528kafkawindowsexe\u5de5\u5177<\/a>\u7a0b\u5e8f\u66f4\u6613\u4e8e\u90e8\u7f72\u548c\u4f7f\u7528\u3002\u8fd9\u4e9b\u6846\u67b6\u4f7f\u7528\u4e86Web\u6280\u672f\u548c\u672c\u5730API\u7684\u7ed3\u5408\uff0c\u53ef\u4ee5\u5728\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9e\u73b0Web\u5e94\u7528\u7a0b\u5e8f\u6240\u5177\u6709\u7684\u529f\u80fd\u548c\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Web\u5e94\u7528\u7a0b\u5e8f\u662f\u4e00\u79cd\u57fa\u4e8e\u4e92\u8054\u7f51\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u4eec\u8fd0\u884c\u5728Web\u670d\u52a1\u5668\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7Web\u6d4f\u89c8\u5668\u6765\u8bbf\u95ee\u3002\u4e0e\u4f20\u7edf\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u4e0d\u540c\uff0cWeb\u5e94\u7528\u7a0b\u5e8f\u4e0d\u9700\u8981\u5b89\u88c5\u548c\u4e0b\u8f7d\uff0c\u7528\u6237\u53ea\u9700\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u5373\u53ef\u3002\u7136\u800c\uff0c\u6709\u65f6\u5019\u6211\u4eec<\/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":[3352,20205,256,832,12],"topic":[],"class_list":["post-17166","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-linux","tag-win11gho","tag-256","tag-832","tag-12"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/17166","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=17166"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/17166\/revisions"}],"predecessor-version":[{"id":17202,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/17166\/revisions\/17202"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=17166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=17166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=17166"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=17166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}