Electron+Vue+pyinstaller服务打包

electron环境安装略

  1. electron的入口文件配置test.js, 需要在package.json 配置文件中指定main: src/test.js

    const { app, BrowserWindow } = require('electron')

    const createWindow = () => {
    const win = new BrowserWindow({
    width: 800,
    height: 600
    })

    // win.loadFile('index.html')

    // 下面的url为自己启动vite项目的url。
    // win.loadURL('http://127.0.0.1:28087/')

     // 在窗口内要展示的内容为 ./dist/index.html,即打包生成的index.html
    
     // mainWindow.loadURL(url.format({
    
     //   pathname: path.join(__dirname, './dist', 'index.html'),
    
     //   protocol: 'file:',
    
     //   slashes: true
    
     // }));
     win.loadFile('./dist/index.html')
    
     // 自动打开调试台
    

    mainWindow.webContents.openDevTools({

     detach: true
    

    });

    }

    app.whenReady().then(() => {
    createWindow()
    app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
    })

    app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
    app.quit()
    }
    })

  2. vue文件单独打包,命令: npm run build, test.js文件在src下, 然后将vue打包的dist文件,需要手动拷贝到src下

  3. 打包electron 命令: electron-builder

关于python服务打包运行, 不需要部署python环境的方式

1.安装依赖, pip install pyinstaller

2.打包服务pyinstaller yourscript.py

具体参见 https://blog.csdn.net/weixin_40025666/article/details/131191945

将py打包程序嵌入到electron启动脚本中, 并将py打包的应用包依赖包复制到/app下

app.on('ready', async () => {
  // 启动服务器exe
  try{ cmd.run(`./app/app.exe`,function(err, data, stderr){
    console.log(data)
    console.log(err)
    console.log(stderr)
  });}
  catch(e){
    console.log(e)
  }

 

  createWindow()
})

其中cmd.run命令需要node安装

npm install node-cmd --save

并在js中引入 const cmd = require('node-cmd');


  1. js本地调试, 运行node js文件即可

  2. 除了node_cmd, 还可以使用组件chile_process调用exe

    var child_process = require('child_process');
    child_process.exec(start cmd.exe /K ping 127.0.0.1);

3.eletron需要打包带进去的文件, 以及文件路径

​
var child_process = require('child_process');
child_process.exec(`start cmd.exe /K ping 127.0.0.1`);

​
相关推荐
喝旺仔la3 小时前
使用vue创建项目
前端·javascript·vue.js
心.c3 小时前
植物大战僵尸【源代码分享+核心思路讲解】
前端·javascript·css·数据结构·游戏·html
喝旺仔la3 小时前
Element Plus中button按钮相关大全
前端·javascript·vue.js
计算机学姐3 小时前
基于SpringBoot+Vue的高校门禁管理系统
java·vue.js·spring boot·后端·spring·intellij-idea·mybatis
柒@宝儿姐3 小时前
Git的下载与安装
前端·javascript·vue.js·git·elementui·visual studio
敲敲敲敲暴你脑袋4 小时前
【cesium】绘制贴地线面和自定义Primitive
javascript·webgl·cesium
曈欣4 小时前
vue 中属性值上变量和字符串怎么拼接
前端·javascript·vue.js
计算机学姐5 小时前
基于SpringBoot+Vue的宠物医院管理系统
java·vue.js·spring boot·后端·mysql·intellij-idea·mybatis
customer085 小时前
【开源免费】基于SpringBoot+Vue.JS教师工作量管理系统(JAVA毕业设计)
java·vue.js·spring boot·后端·开源
缘月叙文5 小时前
vue2项目实现国际化(若依框架示例)
vue.js