{"id":3862,"date":"2023-08-25T15:46:46","date_gmt":"2023-08-25T07:46:46","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=3862"},"modified":"2023-08-25T15:46:46","modified_gmt":"2023-08-25T07:46:46","slug":"htm%e6%89%93%e5%8c%85exe%e6%9c%89%e9%82%a3%e4%ba%9b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/3862\/","title":{"rendered":"htm\u6253\u5305exe\u6709\u90a3\u4e9b\u65b9\u6cd5?"},"content":{"rendered":"

\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u662f\u4e00\u79cd\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5\u3002\u8fd9\u79cd\u6280\u672f\u53ef\u4ee5\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u72ec\u7acb\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u5b83\u4eec\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4ee5\u53ca\u5b9e\u73b0\u8fd9\u79cd\u6280\u672f\u7684\u539f\u7406\u3002<\/p>\n

\u6253\u5305HTML\u6587\u4ef6\u7684\u5de5\u5177<\/p>\n

\u6709\u8bb8\u591a\u5de5\u5177\u53ef\u4ee5\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5176\u4e2d\u6700\u6d41\u884c\u7684\u5de5\u5177\u662fElectron\u548cNW.js\u3002\u8fd9\u4e24\u4e2a\u5de5\u5177\u90fd\u662f\u57fa\u4e8eNode.js\u7684\u6846\u67b6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u4e9b\u5de5\u5177\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u6253\u5305HTML\u3001CSS\u548cJavaScript\u6587\u4ef6\uff0c\u5e76\u5c06\u5b83\u4eec\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u539f\u7406<\/p>\n

\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u539f\u7406\u662f\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u5305\u542bWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u6240\u6709\u8d44\u6e90\uff0c\u5982HTML\u3001CSS\u548cJavaScript\u6587\u4ef6\u3002\u5f53\u7528\u6237\u8fd0\u884c\u8be5\u6587\u4ef6\u65f6\uff0c\u5b83\u5c06\u542f\u52a8\u4e00\u4e2a\u672c\u5730Web\u670d\u52a1\u5668\uff0c\u5e76\u5728\u7528\u6237\u7684\u9ed8\u8ba4\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00Web\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u5728\u6253\u5305HTML\u6587\u4ef6\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5f00\u53d1\u4eba\u5458\u9700\u8981\u6307\u5b9a\u4e00\u4e2a\u5165\u53e3\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u5305\u542bWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u6240\u6709\u903b\u8f91\u4ee3\u7801\u3002\u8be5\u5165\u53e3\u6587\u4ef6\u5c06\u88ab\u6253\u5305\u5230\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\uff0c\u5e76\u5728\u7528\u6237\u8fd0\u884c\u8be5\u6587\u4ef6\u65f6\u81ea\u52a8\u542f\u52a8\u3002<\/p>\n

\u5b9e\u73b0<\/p>\n

\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528Electron\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u7b80\u5355\u793a\u4f8b\u3002<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Electron\uff1a<\/p>\n

“`<\/p>\n

npm install -g electron<\/p>\n

“`<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Electron\u9879\u76ee\uff1a<\/p>\n

“`<\/p>\n

mkdir myapp<\/p>\n

cd myapp<\/p>\n

npm init -y<\/p>\n

“`<\/p>\n

\u7136\u540e\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Electron\u4f9d\u8d56\u9879\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cmain.js\u201d\u7684\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u5c06\u4f5c\u4e3a\u6211\u4eec\u7684\u5165\u53e3\u6587\u4ef6\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u5c06\u542f\u52a8\u4e00\u4e2a\u672c\u5730Web\u670d\u52a1\u5668\uff0c\u5e76\u5728\u7528\u6237\u7684\u9ed8\u8ba4\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00Web\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n

“`<\/p>\n

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

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

ron’)<\/p>\n

const path = require(‘path’)<\/p>\n

const url = require(‘url’)<\/p>\n

let win<\/p>\n

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

win = new BrowserWindow({ width: 800, height: 600 })<\/p>\n

win.loadURL(url.format({<\/p>\n

pathname: path.join(__dirname, ‘index.html’),<\/p>\n

protocol: ‘file:’,<\/p>\n

slashes: true<\/p>\n

}))<\/p>\n

win.on(‘closed’, () => {<\/p>\n

win = null<\/p>\n

})<\/p>\n

}<\/p>\n

app.on(‘ready’, createWindow)<\/p>\n

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

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

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

}<\/p>\n

})<\/p>\n

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

if (win === null) {<\/p>\n

createWindow()<\/p>\n

}<\/p>\n

})<\/p>\n

“`<\/p>\n

\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a\u201cwin\u201d\u7684BrowserWindow\uff0c\u8be5\u7a97\u53e3\u52a0\u8f7d\u4e86\u6211\u4eec\u7684HTML\u6587\u4ef6\uff08index.html\uff09\u3002\u6211\u4eec\u8fd8\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\u4e8b\u4ef6\u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e9b\u903b\u8f91\uff0c\u4ee5\u786e\u4fdd\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u5728\u5173\u95ed\u7a97\u53e3\u65f6\u6b63\u786e\u9000\u51fa\u3002<\/p>\n

\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u5728\u201cpackage.json\u201d\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u201cstart\u201d\u811a\u672c\uff0c\u4ee5\u542f\u52a8\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n

“`<\/p>\n

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

“start”: “electron .”<\/p>\n

},<\/p>\n

“`<\/p>\n

\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n

“`<\/p>\n

npm start<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u542f\u52a8\u4e00\u4e2a\u672c\u5730Web\u670d\u52a1\u5668\uff0c\u5e76\u5728\u7528\u6237\u7684\u9ed8\u8ba4\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00\u6211\u4eec\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Electron\u6253\u5305\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

“`<\/p>\n

electron-packager . MyApp –platform=win32 –arch=x64 –icon=icon.ico –out=dist\/<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cMyApp\u201d\u3001\u56fe\u6807\u4e3a\u201cicon.ico\u201d\u3001\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u768464\u4f4d\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u8f93\u51fa\u5230\u540d\u4e3a\u201cdist\u201d\u7684\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n

\u7ed3\u8bba<\/p>\n

\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u662f\u4e00\u79cd\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Electron\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u8ba8\u8bba\u4e86\u5b9e\u73b0\u8fd9\u79cd\u6280\u672f\u7684\u539f\u7406\u3002\u65e0\u8bba\u60a8\u662f\u4e00\u540dWeb\u5f00\u53d1\u4eba\u5458\u8fd8\u662f\u4e00\u540d\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4eba\u5458\uff0c\u8fd9\u79cd\u6280\u672f\u90fd\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5c06Web\u5e94\u7528\u5982\u4f55\u81ea\u5df1\u5c01\u88c5\u8f6f\u4ef6\u5408\u96c6<\/a>\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u72ec\u7acb\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6237\u628aweb\u9879\u76ee\u5c01\u88c5\u6210exe<\/a>\u4f53\u9a8c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u662f\u4e00\u79cd\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5\u3002\u8fd9\u79cd\u6280\u672f\u53ef\u4ee5\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u72ec\u7acb\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u5b83\u4eec\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec<\/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":[7608,7607,256,12,16],"topic":[],"class_list":["post-3862","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-seleniumexe","tag-webexe","tag-256","tag-12","tag-16"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/3862","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=3862"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/3862\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=3862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=3862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=3862"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=3862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}