{"id":4659,"date":"2023-09-11T13:04:47","date_gmt":"2023-09-11T05:04:47","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=4659"},"modified":"2023-09-11T13:04:47","modified_gmt":"2023-09-11T05:04:47","slug":"winds%e6%89%93%e5%8c%85%e8%8b%b9%e6%9e%9capp%e6%8a%80%e6%9c%af%e5%8e%9f%e7%90%86%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/4659\/","title":{"rendered":"winds\u6253\u5305\u82f9\u679capp\u6280\u672f\u539f\u7406\u4ecb\u7ecd"},"content":{"rendered":"

Winds\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u7528\u4e8e\u5c06web\u5e94\u7528\u6253\u5305\u6210\u53ef\u5728\u591a\u4e2a\u5e73\u53f0\u4e0a\u8fd0\u884c\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4f7f\u7528HTML\u3001CSS\u548cJavaScript\u6784\u5efa\u8de8\u5e73\u53f0\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5c06\u5176\u8f6c\u5316\u4e3a\u9488\u5bf9\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u7684\u539f\u751f\u5e94\u7528\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Winds\u5c06web\u5e94\u7528\u6253\u5305\u6210\u82f9\u679cApp\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n

## \u539f\u7406\u4ecb\u7ecd<\/p>\n

Winds\u7684\u6253\u5305\u539f\u7406\u662f\u57fa\u4e8eElectron\u6846\u67b6\u548cWebpack\u6784\u5efa\u5de5\u5177\u3002Electron\u662f\u4e00\u4e2a\u5141\u8bb8\u5f00\u53d1\u8005\u4f7f\u7528Web\u6280\u672f\u6784\u5efa\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u6e90\u6846\u67b6\uff0c\u5b83\u57fa\u4e8eChromium\u548cNode.js\u3002\u800cWebpack\u662f\u4e00\u4e2a\u6253\u5305\u6784\u5efa\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5c06\u591a\u4e2a\u7f51\u9875\u6a21\u5757\u6253\u5305\u6210\u5c11\u91cf\u7684\u9759\u6001\u8d44\u6e90\u6587\u4ef6\u3002Winds\u4f7f\u7528Webpack\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u72ec\u7acb\u7684Electron\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u3002<\/p>\n

\u5177\u4f53\u6765\u8bf4\uff0cWinds\u7684\u6253\u5305\u8fc7\u7a0b\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n

1. \u521b\u5efaElectron\u5e94\u7528\u7a0b\u5e8f\uff1a\u9996\u5148\uff0c\u9700\u8981\u4f7f\u7528Electron\u7684API\u521b\u5efa<\/p>\n

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

\u4e00\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\uff0c\u8be5\u5e94\u7528\u7a0b\u5e8f\u5c06\u7528\u4e8e\u52a0\u8f7d\u548c\u8fd0\u884cweb\u5e94\u7528\u3002<\/p>\n

2. \u52a0\u8f7dweb\u5e94\u7528\uff1a\u63a5\u4e0b\u6765\uff0c\u5e94\u7528\u7a0b\u5e8f\u4f1a\u52a0\u8f7dweb\u5e94\u7528\u3002Winds\u4f7f\u7528Electron\u7684BrowserWindow\u5bf9\u8c61\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7a97\u53e3\uff0c\u5e76\u52a0\u8f7dweb\u5e94\u7528\u7684\u5165\u53e3\u6587\u4ef6\u3002\u8fd9\u4e2a\u5165\u53e3\u6587\u4ef6\u901a\u5e38\u662f\u4e00\u4e2aHTML\u6587\u4ef6\u3002<\/p>\n

3. \u6253\u5305\u9759\u6001\u8d44\u6e90\uff1aWinds\u4f7f\u7528Webpack\u5c06web\u5e94\u7528\u6253\u5305\u6210\u9759\u6001\u8d44\u6e90\u6587\u4ef6\u3002Webpack\u4f1a\u6839\u636e\u914d\u7f6e\u6587\u4ef6\u5bf9\u5e94\u7528\u7a0b\u5e8f\u7684\u4ee3\u7801\u8fdb\u884c\u9759\u6001\u5206\u6790\uff0c\u5e76\u5c06\u5404\u4e2a\u6a21\u5757\u6253\u5305\u6210\u4e00\u4e2a\u6216\u591a\u4e2aJavaScript\u6587\u4ef6\u3002\u8fd9\u4e9b\u6587\u4ef6\u53ef\u4ee5\u901a\u8fc7script\u6807\u7b7e\u5728web\u9875\u9762\u4e0a\u5f15\u5165\u3002<\/p>\n

4. \u6253\u5305Electron\u5e94\u7528\uff1a\u4e00\u65e6\u9759\u6001\u8d44\u6e90\u6253\u5305\u5b8c\u6210\uff0cWinds\u4f1a\u5c06\u8fd9\u4e9b\u9759\u6001\u8d44\u6e90\u96c6\u6210\u5230Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002\u901a\u8fc7\u5c06\u9759\u6001\u8d44\u6e90\u6587\u4ef6\u548cElectron\u7684\u4e3b\u8fdb\u7a0b\u4ee3\u7801\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u6700\u7ec8\u5f62\u6210\u4e00\u4e2a\u5b8c\u6574\u7684\u6253\u5305\u597d\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

5. \u6784\u5efa\u9002\u914d\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u7684\u5e94\u7528\u7a0b\u5e8f\uff1a\u6700\u540e\uff0cWinds\u4f7f\u7528\u7279\u5b9a\u7684\u5de5\u5177\u548c\u914d\u7f6e\u5c06\u5e94\u7528\u7a0b\u5e8f\u6784\u5efa\u6210\u9002\u914d\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u5728\u6253\u5305\u6210\u82f9\u679cApp\u65f6\uff0c\u9700\u8981\u4f7f\u7528xcode\u5de5\u5177\u548c\u76f8\u5e94\u7684\u914d\u7f6e\u6587\u4ef6\u5bf9\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u6784\u5efa\u3002<\/p>\n

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

\u4e0b\u9762\u662f\u4f7f\u7528Winds\u5c06web\u5e94\u7528\u6253\u5305\u6210\u82f9\u679cApp\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n

1. \u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Node.js\u548cnpm\u3002<\/p>\n

2. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u76ee\u5f55\uff0c\u8fdb\u5165\u8be5\u76ee\u5f55\uff0c\u5e76\u4f7f\u7528npm\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\uff1a<\/p>\n

“`<\/p>\n

$ mkdir winds-app<\/p>\n

$ cd winds-app<\/p>\n

$ npm init -y<\/p>\n

“`<\/p>\n

3. \u5b89\u88c5Winds\u4f9d\u8d56\uff1a<\/p>\n

“`<\/p>\n

$ npm install winds<\/p>\n

“`<\/p>\n

4. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684Electron\u5165\u53e3\u6587\u4ef6\uff0c\u4f8b\u5982`main.js`\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(createWindow);<\/p>\n

“`<\/p>\n

5. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684Webpack\u914d\u7f6e\u6587\u4ef6\uff0c\u4f8b\u5982`webpack.config.js`\uff1a<\/p>\n

“`<\/p>\n

module.exports = {<\/p>\n

entry: ‘.\/src\/index.js’,<\/p>\n

output: {<\/p>\n

filename: ‘bundle.js’,<\/p>\n

\u82f9\u679c\u6e90\u7801\u6253\u5305app<\/a> path: __dirname + ‘\/dist’,<\/p>\n

},<\/p>\n

};<\/p>\n

“`<\/p>\n

6. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684HTML\u6587\u4ef6\uff0c\u4f8b\u5982`index.html`\uff0c\u5e76\u5728\u5176\u4e2d\u5f15\u5165\u6253\u5305\u751f\u6210\u7684JavaScript\u6587\u4ef6\uff1a<\/p>\n

“`<\/p>\n<\/p>\n

\n

\n

Winds App<\/title><\/p>\n<\/p>\n<p>\n<\/p>\n<p>“`<\/p>\n<p>7. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684JavaScript\u6587\u4ef6\uff0c\u4f8b\u5982`index.js`\uff0c\u5e76\u7f16\u5199\u4f60\u7684web\u5e94\u7528\u7a0b\u5e8f\u903b\u8f91\u3002<\/p>\n<p>8. \u5728`package.json`\u4e2d\u6dfb\u52a0\u4ee5\u4e0bscripts\uff1a<\/p>\n<p>“`<\/p>\n<p>“scrip<a href=\"https:\/\/www.applebyme.vip\/pingguo-dabao-153\">\u82f9\u679c\u624b\u673a\u8f6f\u4ef6\u6253\u5305\u7528\u4ec0\u4e48app<\/a>ts”: {<\/p>\n<p> “start”: “electron .”,<\/p>\n<p> “package:mac”: “winds build -t mac”,<\/p>\n<p> “package:windows”: “winds build -t windows”,<\/p>\n<p> “package:linux”: “winds build -t linux”<\/p>\n<p>},<\/p>\n<p>“`<\/p>\n<p>9. \u8fd0\u884c\u547d\u4ee4\u4ee5\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n<p>“`<\/p>\n<p>$ npm start<\/p>\n<p>“`<\/p>\n<p>10. \u8fd0\u884c\u547d\u4ee4\u4ee5\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u4e3a\u82f9\u679cApp\uff1a<\/p>\n<p>“`<\/p>\n<p>$ npm run package:mac<\/p>\n<p>“`<\/p>\n<p>\u4ee5\u4e0a\u662f\u4f7f\u7528Winds\u5c06web\u5e94\u7528\u6253\u5305\u6210\u82f9\u679cApp\u7684\u7b80\u8981\u6b65\u9aa4\u3002\u5177\u4f53\u7684\u914d\u7f6e\u548c\u547d\u4ee4\u53ef\u80fd\u4f1a\u6709\u6240\u8c03\u6574\uff0c\u53ef\u4ee5\u53c2\u8003Winds\u7684\u5b98\u65b9\u6587\u6863\u83b7\u53d6\u66f4\u591a\u8be6\u7ec6\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u603b\u7ed3\u8d77\u6765\uff0cWinds\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65b9\u4fbf\u7684\u65b9\u5f0f\u5c06web\u5e94\u7528\u6253\u5305\u6210\u539f\u751f\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u4e0d\u540c\u5e73\u53f0\u4e0a\u8fdb\u884c\u90e8\u7f72\u3002\u901a\u8fc7\u4e86\u89e3Winds\u7684\u539f\u7406\u548c\u4f7f\u7528\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u66f4\u597d\u5730\u5229\u7528\u8fd9\u4e2a\u5de5\u5177\u6765\u6784\u5efa\u8de8\u5e73\u53f0\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Winds\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u7528\u4e8e\u5c06web\u5e94\u7528\u6253\u5305\u6210\u53ef\u5728\u591a\u4e2a\u5e73\u53f0\u4e0a\u8fd0\u884c\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4f7f\u7528HTML\u3001CSS\u548cJavaScript\u6784\u5efa\u8de8\u5e73\u53f0\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5c06\u5176\u8f6c\u5316\u4e3a\u9488\u5bf9\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u7684\u539f\u751f<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[2325,12,16,5432,8916],"topic":[],"class_list":["post-4659","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-2325","tag-12","tag-16","tag-app"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/4659","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\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=4659"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/4659\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=4659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=4659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=4659"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=4659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}