electron引入vue(Vue使用electron转换项目成桌面应用方法介绍)
导读:1、将已有 Vue 项目打包。...
1 、将已有 Vue 项目打包 。
2 、新建 main.js 、package.json 文件
将打包生成的 index.html 、js 、css 、然后再和新建的 main.js 、package.json 文件 放至一个目录下 。并命令行切换至这个目录 。
新建的 main.js 如下:
新建的 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 、安装包:
yarn install
(报错不用管 ,能 electron . 运行成功且效果正常就行)
4 、运行:
electron .
5 、注意事项:
vue 项目 路由用 hash 模式 。 vue 项目 的 vue.config.js 要配置 publicPath: ./(因为若不配置 ,则 electron 文件路径不对)
module.exports = {
lintOnSave: false,
publicPath: ./,
css: ....
....
}
index.html 中文件路径如以下正确显示:
<link rel="icon" href="" rel="external nofollow" >
<title>efficiency-helper</title>
<link href="https://www.jb51.net/article/css/chunk-11991773.33db9af5.css" rel="external nofollow" rel="prefetch">
<link href="https://www.jb51.net/article/css/chunk-17ca335a.ad6ca46b.css" rel="external nofollow" rel="prefetch">
<link href="https://www.jb51.net/article/css/chunk-3dde8fae.019eaf8d.css" rel="external nofollow" rel="prefetch">
<link href="https://www.jb51.net/article/css/chunk-4c9aec9b.410cb728.css" rel="external nofollow" rel="prefetch">
<link href="https://www.jb51.net/article/css/chunk-f52405ee.f4abe7d9.css" rel="external nofollow" rel="prefetch">
若不配置 publicPath: ./ 则:href=“/css/chunk-17ca335a.ad6ca46b.css ” 路径错误 。导致应用出现白屏 。
到此这篇关于Vue使用electron转换项目成桌面应用方法介绍的文章就介绍到这了,更多相关Vueelectron内容请搜索本站以前的文章或继续浏览下面的相关文章希望大家以后多多支持本站!
声明:本站所有文章 ,如无特殊说明或标注 ,均为本站原创发布 。任何个人或组织 ,在未征得本站同意时 ,禁止复制 、盗用 、采集、发布本站内容到任何网站 、书籍等各类媒体平台 。如若本站内容侵犯了原著者的合法权益 ,可联系我们进行处理 。
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!