{"id":2715,"date":"2023-08-11T15:47:33","date_gmt":"2023-08-11T07:47:33","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=2715"},"modified":"2023-08-11T15:47:33","modified_gmt":"2023-08-11T07:47:33","slug":"html%e5%8f%af%e4%bb%a5%e6%89%93%e5%8c%85%e6%88%90exe%e5%90%97","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/2715\/","title":{"rendered":"html\u53ef\u4ee5\u6253\u5305\u6210exe\u5417?"},"content":{"rendered":"

HTML\u672c\u8eab\u662f\u4e00\u79cd\u6807\u8bb0\u8bed\u8a00\uff0c\u4e0d\u662f\u4e00\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u672c\u8eab\u5e76\u4e0d\u80fd\u88ab\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f46\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u5de5\u5177\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e24\u79cd\u5c06HTML\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u65b9\u6cd5\u3002<\/p>\n

\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528Electron<\/p>\n

Electron\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u4f7f\u7528Web\u6280\u672f\uff08HTML\u3001CSS\u548cJavaScript\uff09\u521b\u5efa\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u4f7f\u7528Electron\u6253\u5305HTML\u6587\u4ef6\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

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

\u9996\u5148\uff0c\u9700\u8981\u5728\u672c\u5730\u5b89\u88c5Electron\u3002\u53ef\u4ee5\u901a\u8fc7npm\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

\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u672c\u5730\u5b89\u88c5Electron\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u9879\u76ee\u7684\u5f00\u53d1\u4f9d\u8d56\u4e2d\u3002<\/p>\n

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

\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cmain.js\u201d\u7684\u6587\u4ef6\uff0c\u5e76\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

“`<\/p>\n

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

const path = require(‘path’\u4e3adeepin\u5f00\u53d1\u8f6f\u4ef6<\/a>)<\/p>\n

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

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

width: 800,<\/p>\n

height: 600,<\/p>\n

webPreferences: {<\/p>\n

preload: path.join(__dirname, ‘preload.js’)<\/p>\n

}<\/p>\n

})<\/p>\n

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

}<\/p>\n

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

createWindow()<\/p>\n

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

if (BrowserWindow.getAllWexe\u6253\u5305\u4e3awindow\u670d\u52a1<\/a>indows().length === 0) createWindow()<\/p>\n

})<\/p>\n

})<\/p>\n

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

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

})<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u4ee3\u7801\u4f1a\u521b\u5efa\u4e00\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5728\u7a97\u53e3\u4e2d\u52a0\u8f7d\u201cindex.html\u201d\u6587\u4ef6\u3002<\/p>\n

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

\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n

“`<\/p>\n

electron-packager . MyAppName –platform=win32 –arch=x64<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u540d\u4e3a\u201cMyAppName\u201d\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u5728Windows\u5e73\u53f0\u4e0a\u8fd0\u884c\u3002<\/p>\n

\u65b9\u6cd5\u4e8c\uff1a\u4f7f\u7528NW.js<\/p>\n

NW.js\u662f\u53e6\u4e00\u4e2a\u5f00\u6e90\u6846\u67b6\uff0c\u5b83\u4e5f\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u4f7f\u7528Web\u6280\u672f\uff08HTML\u3001CSS\u548cJavaScript\uff09\u521b\u5efa\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u4f7f\u7528NW.js\u6253\u5305HTML\u6587\u4ef6\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

1.<\/p>\n

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

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

\u540c\u6837\uff0c\u9700\u8981\u5728\u672c\u5730\u5b89\u88c5NW.js\u3002\u53ef\u4ee5\u901a\u8fc7npm\u6765\u5b89\u88c5NW.js\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u672c\u5730\u5b89\u88c5NW.js\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u9879\u76ee\u7684\u5f00\u53d1\u4f9d\u8d56\u4e2d\u3002<\/p>\n

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

\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cpackage.json\u201d\u7684\u6587\u4ef6\uff0c\u5e76\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

“`<\/p>\n

{<\/p>\n

“name”: “MyAppName”,<\/p>\n

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

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

“icon”: “icon.png”,<\/p>\n

“toolbar”: false,<\/p>\n

“frame”: true,<\/p>\n

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

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

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u4ee3\u7801\u4f1a\u521b\u5efa\u4e00\u4e2aNW.js\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5728\u7a97\u53e3\u4e2d\u52a0\u8f7d\u201cindex.html\u201d\u6587\u4ef6\u3002<\/p>\n

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

\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n

“`<\/p>\n

nwbuild -p win64 .<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2aWindows\u5e73\u53f0\u4e0a\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

\u4ee5\u4e0a\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4f46\u662fElectron\u548cNW.js\u7684\u5e94\u7528\u573a\u666f\u6709\u6240\u4e0d\u540c\u3002\u5982\u679c\u9700\u8981\u521b\u5efa\u529f\u80fd\u8f83\u4e3a\u590d\u6742\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528Electron\uff1b\u5982\u679c\u53ea\u9700\u8981\u5c06\u4e00\u4e2a\u7b80\u5355\u7684\u7f51\u9875\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528NW.js\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

HTML\u672c\u8eab\u662f\u4e00\u79cd\u6807\u8bb0\u8bed\u8a00\uff0c\u4e0d\u662f\u4e00\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u672c\u8eab\u5e76\u4e0d\u80fd\u88ab\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f46\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u5de5\u5177\u5c06HTML\u6587\u4ef6\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e24\u79cd\u5c06HTML\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u65b9\u6cd5\u3002\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528E<\/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":[256,832,12,3565,5601],"topic":[],"class_list":["post-2715","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-256","tag-832","tag-12","tag-exe"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2715","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=2715"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/2715\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=2715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=2715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=2715"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=2715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}