
1、将已有 vue 项目打包。
将打包生成的 index.html、js、CSS、然后再和新建的 main.js、package.JSON 文件 放至一个目录下。并命令行切换至这个目录。
新建的 main.js 如下:
const { APP, Browserwindow } = reqUIre("electron"); // 引入electron let win; let windowConfig = { width: 800, height: 600, }; // 窗口的大小 function createWindow() { win = new BrowserWindow(windowConfig); // 创建一个窗口 win.loadurl(`file://${__dirname}/index.HTML`); // 加载打包生成的index.html win.WEBContents.openDevTools(); // 开启调试工具 win.on("close", () => { //回收 BrowserWindow 对象 win = null; }); win.on("resize", () => { win.reload(); }); } app.on("ready", createWindow); App.on("window-all-closed", () => { app.quit(); }); app.on("activate", () => { if (win == Null) { createWindow(); } });
新建的 package.json 如下:
{
"name": "demo",
"PRoductName": "项目名称",
"author": "作者",
"version": "1.0.4",
"main": "main.js",
"description": "项目描述",
"scripts": {
"pack": "electron-builder --dir",
"dist": "electron-builder",
"postinstall": "electron-builder install-app-deps"
},
"build": {
"electronVersion": "1.8.4",
"win": {
"requestedExecutionLevel": "highestAvailable",
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
]
},
"AppID": "demo",
"artifactName": "demo-${version}-${arch}.${ext}",
"nsis": {
"artifactName": "demo-${version}-${arch}.${ext}"
},
"extraResources": [
{
"from": "./static/xxxx/",
"to": "app-server",
"filter": [
"**/*"
]
}
]
},
"dependencies": {
"core-js": "^2.4.1",
"electron-packager": "^12.1.0",
"electron-updater": "^2.22.1"
},
"devDependencIEs": {
"electron-forge": "^5.2.4"
}
}3、安装包:
(报错不用管,能 electron . 运行成功且效果正常就行)
4、运行:
electron .
5、注意事项:
(因为若不配置,则 electron 文件路径不对)
module.Exports = { lintOnSave: false, publicPath: './', css: .... .... }
index.html 中文件路径如以下正确显示:
<link rel="icon" href="favicon.ico" rel="external nofollow" > <title>efficiency-helper</title> <link href="css/chunk-11991773.33Db9af5.css" rel="external Nofollow" rel="prefetch"> <link href="css/chunk-17ca335a.ad6ca46b.css" rel="external nofollow" rel="preFetch"> <link href="css/chunk-3dde8fae.019eaf8d.css" rel="external nofollow" rel="prefetch"> <link href="css/chunk-4c9aec9b.410cb728.css" rel="external nofollow" rel="prefetch"> <link href="css/chunk-f52405ee.f4abe7d9.css" rel="external nofollow" rel="prefetch">
若不配置 publicPath: './' 则:href=“/css/chunk-17ca335a.ad6ca46b.css” 路径错误。导致应用出现白屏。




网友评论文明上网理性发言 已有0人参与
发表评论: