首页 > 编程语言 >Electron打包若依前端为桌面程序

Electron打包若依前端为桌面程序

时间:2023-06-20 15:22:29浏览次数:33  
标签:桌面 process win app electron 若依 -- Electron true

下面的步骤是我事后整理的,还需要第二个项目进行验证,才能知道是否完整。

1.npm install electron --save-dev

2.npm install electron-builder 

3.设置图标的:npm install electron-icon-builder 

3.打开env.development文件 修改:VUE_APP_BASE_API = '线上地址/prod-api'

4.在package.json里面的script节点之前插入:main: "background.js"。

5.在src文件夹下建立background.js,内容如下:

'use strict'
import { app, protocol, BrowserWindow, ipcMain, Menu} from 'electron'
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
import path from 'path'
const isDevelopment = process.env.NODE_ENV !== 'production'
const Store = require('electron-store');

// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
{ scheme: 'app', privileges: { secure: true, standard: true } }
])

async function createWindow() {

Menu.setApplicationMenu(null) // null值取消顶部菜单栏
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
contextIsolation:false, //上下文隔离
enableRemoteModule: true, //启用远程模块
nodeIntegration: true, //开启自带node环境
webviewTag: true, //开启webview
webSecurity: false,
allowDisplayingInsecureContent: true,
allowRunningInsecureContent: true
}
})
win.maximize()
win.show()
win.webContents.openDevTools()
ipcMain.on('getPrinterList', (event) => {
//主线程获取打印机列表
win.webContents.getPrintersAsync().then(data=>{
win.webContents.send('getPrinterList', data);
});
//通过webContents发送事件到渲染线程,同时将打印机列表也传过去

});

if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
if (!process.env.IS_TEST) win.webContents.openDevTools()
} else {
createProtocol('app')
// Load the index.html when not in development
win.loadURL('app://./index.html')


}
}

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', async () => {
Store.initRenderer();
if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools
try {
await installExtension(VUEJS_DEVTOOLS)
} catch (e) {
console.error('Vue Devtools failed to install:', e.toString())
}
}
createWindow()
})

// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {

if (process.platform === 'win32') {
process.on('message', (data) => {
if (data === 'graceful-exit') {
app.quit()
}
})
} else {
process.on('SIGTERM', () => {
app.quit()
})
}
}

6.在package.json里面的script节点插入:

"electron:serve": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service electron:serve",
"electron:build": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service electron:build",
"electron:build:win32": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service electron:build --win --ia32",
"electron:generate-icons": "electron-icon-builder --input=./src/assets/logo/logo.png --output=build --flatten"

进行打包 npm run electron:build // 打包命令

打包成功后会在dist_electron中生成了exe文件,点击安装即可。

7.执行命令:

产生icon文件夹:npm run electron:generate-icons

打包生成: npm run electron:build

最后:./src/assets/logo/logo.png的图片最好是1024,要不然生成后的图标,可能在exe程序上显示不全。

标签:桌面,process,win,app,electron,若依,--,Electron,true
From: https://www.cnblogs.com/sheizhuchenfu2/p/17493729.html

相关文章

  • 使用nwjs打包VUE生成桌面应用
    摘抄自:https://blog.csdn.net/weixin_40521770/article/details/126907614目前已知把Vue项目打包成桌面应用有两种方式:(1)使用nwjs生成桌面应用;(2)使用Electron生成桌面应用。本文采用的是nwjs生成桌面应用,也是我认为最简单、最快捷的一种。一、打包Vue应用程序npmrunbuild二、添......
  • electron 无边框窗口拖拽移动问题记录及解决办法
    在做一款uTools的插件,悬浮文本窗口是没有标题栏的,所以需要找一个地方可以拖动移动位置就开始了接下来的踩坑记录项目结构只是一个简单的容器元素,一个多行文本框容器元素加一个内边距,然后这个内边距区域就是我理想的可拖动位置<body><divid="container"><texta......
  • 若依框架 前后端分离如何通过菜单管理添加菜单?
    1、创建主目录菜单,如图: 路由地址填写views下的文件名,目录结构参考如下:2、创建子菜单,点击新增 3、填写子菜单信息,参考如下: 路由地址填写:views下的二级文件夹名字组件路径填写为:views下到index.vue的路径(不要写文件后缀),例如:publish/mipsMaterialFiles/index权限字符......
  • Windows 显示 桌面图标 计算机 控制面板 网络 图标 批处理
    powershellstart-process-verbrunascmd@echooffremShowComputericonondesktopregadd"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel"/v"{20D04FE0-3AEA-1069-A2D8-08002B303......
  • 华为手机使用第三方桌面
    手里有个荣耀v10,系统为EMUI9。安装了极简桌面,准备给老人用。但是华为从EMUI9开始,禁用了第三方桌面。解决办法:打开开发者选项-USB调试,连接电脑;在手机上安装小黑屋。可以在这里下载,https://www.coolapk.com/apk/web1n.stopapp,然后adbinstallxxx.apk打开小黑屋,选择麦......
  • Journal of Electronic Imaging投稿分享
    JournalofElectronicImaging投稿分享在研究生阶段中的第一篇论文,前后总共三个月,还是很开心的!!!附下中稿图片 这个期刊从二月份开始投的,然后三月份给了大修,大修时间一个月。在四月份左右提交了修改稿,最终五月份就给了录用通知!总的来说,速度还是很快的。附下两次的审稿进度。......
  • Windows远程桌面如何用空密码登录远程桌面
    1.运行组策略:gpedit.msc快捷键win+r键,输入gpedit.msc点击确定 2.在计算机配置>Windows设置>安全设置>本地策略>安全选项中,找到:帐户:使用空密码的本地帐户只允许进行控制台登录。 3. 设置为:已禁用。 ......
  • [-003-]-Python3+Unittest+Uiautomation Windows桌面App UI自动化之控件查找
    1、获取所有的子控件:control.GetChildren()2、获取首个子控件:control.GetFirstChildControl()3、获取最后一个子控件:control.GetLastChildControl()4、获取下一个兄弟控件:control.GetNextSiblingControl()5、获取前一个兄弟控件:control.GetPreviousSiblingContr......
  • 【Windows】百度网盘桌面“同步空间”图标删除
    ✨百度网盘桌面“同步空间”图标桌面出现“同步空间图标”右键无法删除✨解决方案搜索注册表编辑器或者regedit在注册表编辑器中,编辑>查找:同步空间,删除相关项!注意:搜索出来同步空间相关项较多,如仅需删除桌面图标请直接定位到计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Mic......
  • [-002-]-Python3+Unittest+Uiautomation Windows桌面App UI自动化之鼠标操作
    1、单击鼠标左键Click(x:int,y:int,waitTime:float=OPERATION_WAIT_TIME)模拟鼠标在点x,y的点击。OPERATION_WAIT_TIME默认为0.5即等待时间默认为0.5秒2、单击鼠标中键MiddleClick(x:int,y:int,waitTime:float=OPERATION_WAIT_TIME)模拟鼠标在点x,y......