{"id":19440,"date":"2024-03-15T09:42:42","date_gmt":"2024-03-15T01:42:42","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=19440"},"modified":"2024-03-15T09:42:42","modified_gmt":"2024-03-15T01:42:42","slug":"web%e8%bd%ac%e6%a1%8c%e9%9d%a2%e5%ba%94%e7%94%a8%e6%93%8d%e4%bd%9c%e5%8a%9e%e6%b3%95%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2024\/03\/15\/web%e8%bd%ac%e6%a1%8c%e9%9d%a2%e5%ba%94%e7%94%a8%e6%93%8d%e4%bd%9c%e5%8a%9e%e6%b3%95%e4%bb%8b%e7%bb%8d\/","title":{"rendered":"web\u8f6c\u684c\u9762\u5e94\u7528\u64cd\u4f5c\u529e\u6cd5\u4ecb\u7ecd"},"content":{"rendered":"

\u968f\u7740\u4e92\u8054\u7f51\u6280\u672f\u7684\u53d1\u5c55\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u5e94\u7528\u7a0b\u5e8f\u90fd\u662f\u57fa\u4e8eWeb\u6280\u672f\u6765\u5f00\u53d1\u7684\u3002Web\u5e94\u7528\u5177\u6709\u8de8\u5e73\u53f0\u3001\u6613\u7ef4\u62a4\u3001\u6613\u90e8\u7f72\u7b49\u4f18\u70b9\uff0c\u53d7\u5230\u4e86\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4f46\u662f\uff0cWeb\u5e94\u7528\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\u4e5f\u5b58\u5728\u4e00\u4e9b\u4e0d\u8db3\uff0c\u6bd4\u5982\u79bb\u7ebf\u4f7f\u7528\u3001\u7cfb\u7edf\u7ea7\u522b\u7684\u529f\u80fd\u7b49\u3002\u8fd9\u65f6\u5019\uff0c\u5c06Web\u5e94\u7528\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u5c31\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002\u672c\u6587\u5c06\u4ece\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\u4e24\u4e2a\u65b9\u9762\uff0c\u4ecb\u7ecd\u5982\u4f55\u5c06Web\u5e94\u7528\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u3002<\/p>\n

\u4e00\u3001\u539f\u7406<\/p>\n

\u5c06Web\u5e94\u7528\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u7684\u539f\u7406\u662f\u901a\u8fc7\u5c06Web\u5e94\u7528\u5305\u88c5\u6210\u4e00\u4e2a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u6765\u5b9e\u73b0\u3002\u8fd9\u4e2a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u4f1a\u5728\u7528\u6237\u7684\u8bbe\u5907\u4e0a\u8fd0\u884c\uff0c\u800c\u4e0d\u662f\u5728Web\u6d4f\u89c8\u5668\u4e2d\u3002\u8fd9\u4e2a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u4f1a\u901a\u8fc7Web\u89c6\u56fe\u6765\u52a0\u8f7dWeb\u5e94\u7528\uff0c\u5e76\u5c06Web\u5e94\u7528\u7684\u754c\u9762\u548c\u529f\u80fd\u5448\u73b0\u7ed9\u7528\u6237\u3002<\/p>\n

\u5177\u4f53\u6765\u8bf4\uff0c\u5c06Web\u5e94\u7528\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n

1. \u521b\u5efa\u4e00\u4e2a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\uff1a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\u662f\u4e00\u4e2a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u7684\u4f5c\u7528\u662f\u5c06Web\u5e94\u7528\u5305\u88c5\u6210\u4e00\u4e2a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u3002\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\u8d1f\u8d23\u52a0\u8f7dWeb\u89c6\u56fe\uff0c\u5e76\u5c06Web\u5e94\u7528\u7684\u754c\u9762\u548c\u529f\u80fd\u5448\u73b0\u7ed9\u7528\u6237\u3002<\/p>\n

2. \u5c06Web\u5e94\u7528\u6253\u5305\u4e3a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\uff1a\u5c06Web\u5e94\u7528\u6253\u5305\u4e3a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u4f7f\u7528\u76f8\u5173\u7684\u5de5\u5177\u548c\u6280\u672f\u3002\u6253\u5305\u7684\u8fc7\u7a0b\u4e2d\u9700\u8981\u5c06Web\u5e94\u7528\u7684\u6240\u6709\u6587\u4ef6\u6253\u5305\u5230\u4e00\u4e2a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u5e76\u5c06\u5176\u4e0e\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u6846\u9879\u76ee\u6253\u5305\u6210exe\u8f6f\u4ef6<\/a>\u67b6\u5173\u8054\u3002<\/p>\n

3. \u5b89\u88c5\u548c\u8fd0\u884c\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\uff1a\u5b89\u88c5\u548c\u8fd0\u884c\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u7528\u6237\u624b\u52a8\u5b8c\u6210\u3002\u7528\u6237\u9700\u8981\u4e0b\u8f7d\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5c06\u5176\u5b89\u88c5\u5230\u81ea\u5df1\u7684\u8bbe\u5907\u4e0a\u3002\u4e4b\u540e\u7528\u6237\u53ef\u4ee5\u50cf\u8fd0\u884c\u5176\u4ed6\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u4e00\u6837\u8fd0\u884c\u8be5\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u4e8c\u3001\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n

\u5c06Web\u5e94\u7528\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u7684\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u4e0b\u9762\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u6bd4\u8f83\u5e38\u7528\u7684\u65b9\u5f0f\u3002<\/p>\n

1. \u4f7f\u7528Electron\u6253\u5305Web\u5e94\u7528<\/p>\n

Electron\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5c06Web\u5e94\u7528\u6253\u5305\u4e3a\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002Electron\u7684\u539f\u7406\u662f\u901a\u8fc7\u5c06Web\u5e94\u7528\u6253\u5305\u5230\u4e00\u4e2a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u5e76\u4f7f\u7528Chromium\u4f5c\u4e3aWeb\u89c6\u56fe\uff0c\u4f7f\u5f97Web\u5e94\u7528\u53ef\u4ee5\u50cf\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u4e00\u6837\u8fd0\u884c\u3002<\/p>\n

\u4f7f\u7528Electron\u6253\u5305Web\u5e94\u7528\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

\uff081\uff09\u5b89\u88c5Electron<\/p>\n

\u4f7f\u7528npm\u5b89\u88c5Electron\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

\uff082\uff09\u521b\u5efaElectron\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u521b\u5efa\u4e00\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\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.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-cl\u524d\u7aefvue\u9879\u76ee\u6253\u5305\u6210exe<\/a>osed’, () => {<\/p>\n

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

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

}<\/p>\n

})<\/p>\n

“`<\/p>\n

\uff083\uff09\u6253\u5305Web\u5e94\u7528<\/p>\n

\u4f7f\u7528Electron-builder\u6253\u5305Web\u5e94\u7528\uff1a<\/p>\n

“`<\/p>\n

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

“`<\/p>\n

\u914d\u7f6eElectron-builder\uff1a<\/p>\n

“`<\/p>\n

{<\/p>\n

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

“version”: “1.0.0”,<\/p>\n

“description”: “My App”,<\/p>\n

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

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

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

“pack”: “electron-builder –dir”,<\/p>\n

“dist”: “electron-builder”<\/p>\n

},<\/p>\n

“author”: “My Name”,<\/p>\n

“license”: “MIT”,<\/p>\n

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

“electron”: “^12.0.0”,<\/p>\n

“electron-builder”: “^22.10.5”<\/p>\n

},<\/p>\n

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

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

“productName”: “My App”,<\/p>\n

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

“output”: “dist”<\/p>\n

},<\/p>\n

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

“target”: “nsis”<\/p>\n

},<\/p>\n

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

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

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

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

“installerIcon”: “build\/icon.ico”,<\/p>\n

“uninstallerIcon”: “build\/icon.ico”,<\/p>\n

“installerHeaderIcon”: “build\/icon.ico”,<\/p>\n

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

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

“shortcutName”: “My App”<\/p>\n

}<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u6253\u5305Web\u5e94\u7528\uff1a<\/p>\n

“`<\/p>\n

npm run dist<\/p>\n

“<\/p>\n

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

`<\/p>\n

2. \u4f7f\u7528NW.js\u6253\u5305Web\u5e94\u7528<\/p>\n

NW.js\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5c06Web\u5e94\u7528\u6253\u5305\u4e3a\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002NW.js\u7684\u539f\u7406\u548cElectron\u7c7b\u4f3c\uff0c\u4e5f\u662f\u901a\u8fc7\u5c06Web\u5e94\u7528\u6253\u5305\u5230\u4e00\u4e2a\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u5e76\u4f7f\u7528Chromium\u4f5c\u4e3aWeb\u89c6\u56fe\uff0c\u4f7f\u5f97Web\u5e94\u7528\u53ef\u4ee5\u50cf\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u4e00\u6837\u8fd0\u884c\u3002<\/p>\n

\u4f7f\u7528NW.js\u6253\u5305Web\u5e94\u7528\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

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

\u4e0b\u8f7dNW.js\u5b89\u88c5\u5305\u5e76\u5b89\u88c5\u3002<\/p>\n

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

\u521b\u5efa\u4e00\u4e2aNW.js\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n

“`<\/p>\n

{<\/p>\n

“name<\/p>\n","protected":false},"excerpt":{"rendered":"

\u968f\u7740\u4e92\u8054\u7f51\u6280\u672f\u7684\u53d1\u5c55\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u5e94\u7528\u7a0b\u5e8f\u90fd\u662f\u57fa\u4e8eWeb\u6280\u672f\u6765\u5f00\u53d1\u7684\u3002Web\u5e94\u7528\u5177\u6709\u8de8\u5e73\u53f0\u3001\u6613\u7ef4\u62a4\u3001\u6613\u90e8\u7f72\u7b49\u4f18\u70b9\uff0c\u53d7\u5230\u4e86\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4f46\u662f\uff0cWeb\u5e94\u7528\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\u4e5f\u5b58\u5728\u4e00\u4e9b\u4e0d\u8db3\uff0c\u6bd4\u5982\u79bb\u7ebf\u4f7f\u7528\u3001\u7cfb\u7edf\u7ea7\u522b\u7684<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[19517,11529,116,963,52],"topic":[],"class_list":["post-19440","post","type-post","status-publish","format-standard","hentry","category-zhuomianruanjian","tag-windows10","tag-exe","tag-116","tag-963","tag-52"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/19440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=19440"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/19440\/revisions"}],"predecessor-version":[{"id":19447,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/19440\/revisions\/19447"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=19440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=19440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=19440"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=19440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}