uniapp项目打包为桌面应用的方法步骤

作者:China_Lzw 时间:2024-04-29 13:16:04 

安装electron


cnpm install electron -g

安装electron-packager


cnpm install electron-packager -g

uniapp的manifest.json修改

uniapp项目打包为桌面应用的方法步骤

H5打包

uniapp项目打包为桌面应用的方法步骤

H5文件夹下新建package.json和main.js

uniapp项目打包为桌面应用的方法步骤

新建package.json


{
 "name"    : "app-name",
 "version" : "0.1.0",
 "main"    : "main.js"
}

新建main.js


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

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win

function createWindow () {
 // Create the browser window.
 win = new BrowserWindow({width: 800, height: 600})

// and load the index.html of the app.
 win.loadURL(url.format({
   pathname: path.join(__dirname, 'index.html'),
   protocol: 'file:',
   slashes: true
 }))

// Open the DevTools.
 // win.webContents.openDevTools()

// Emitted when the window is closed.
 win.on('closed', () => {
   // Dereference the window object, usually you would store windows
   // in an array if your app supports multi windows, this is the time
   // when you should delete the corresponding element.
   win = null
 })
}

// 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', createWindow)

// 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 (win === null) {
   createWindow()
 }
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

打包

建议使用cmd,本人使用powershell和git hash有踩坑
按shift+右键根目录,或者cd 你的目录

cmd命令行进入H5目录,输入打包命令

electron-packager . 可执行文件的文件名 --win --out 打包成的文件夹名 --arch=x64位还是32位 --electron-version版本号(不是你的h5版本号,是electron版本号) --overwrite --ignore=node_modules

打包示例


electron-packager . MyApp --win --out MyApp --arch=x64 --electron-version 1.0.0 --overwrite --ignore=node_modules

参考

https://ext.dcloud.net.cn/plugin?id=2905
https://www.cnblogs.com/shangrao/p/14661884.html

来源:uniapp项目打包为桌面应用

标签:uniapp,打包,桌面应用
0
投稿

猜你喜欢

  • google广告之另类js调用实现代码

    2024-05-11 09:44:21
  • 请给PNG8一个机会:对png8的误解

    2009-09-21 10:45:00
  • 面试官常问之说说js中var、let、const的区别

    2024-05-09 15:06:58
  • python字符串替换的2种方法

    2022-12-27 20:59:24
  • Android App端与PHP Web端的简单数据交互实现示例

    2023-07-02 08:16:16
  • python实现websocket的客户端压力测试

    2023-09-30 11:19:57
  • sql server 中合并某个字段值的实例

    2024-01-13 02:39:59
  • 深入理解Django的中间件middleware

    2023-05-11 18:29:46
  • Web页面空间利用率的思考

    2009-07-03 12:45:00
  • 移动端点击图片放大特效PhotoSwipe.js插件实现

    2024-04-28 10:21:02
  • SQLserver中的declare变量用法

    2024-01-18 22:40:19
  • Python 私有化操作实例分析

    2022-11-06 05:44:42
  • Django模板获取field的verbose_name实例

    2023-07-30 06:53:55
  • php 仿Comsenz安装效果代码打包提供下载

    2024-05-11 09:46:37
  • Python HTTP客户端自定义Cookie实现实例

    2023-12-16 01:19:30
  • MySql忘记密码修改方式适应5.7以上版本

    2024-01-28 08:58:43
  • asp中获取当前页面的地址与参数的函数代码

    2011-02-20 10:37:00
  • ASP GetRef 函数指针试探

    2011-03-16 11:09:00
  • 用好Frontpage中的各种回车

    2008-02-21 14:33:00
  • Python中正则表达式的用法实例汇总

    2021-10-02 07:48:08
  • asp之家 网络编程 m.aspxhome.com