How to package the uniapp project as a desktop application

How to package the uniapp project as a desktop application

Installing Electron

cnpm install electron -g

Install electron-packager

cnpm install electron-packager -g

uniapp's manifest.json modification

insert image description here

H5 packaging

insert image description here

Create package.json and main.js in the H5 folder

insert image description here

Create a new package.json

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

Create main.js

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

// Keep a global reference to 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.

Pack

It is recommended to use cmd. I have encountered some problems using powershell and git hash. Press shift+right click on the root directory, or cd to your directory.

Enter the H5 directory using the cmd command line and enter the packaging command

electron-packager . Executable file name --win --out packaged folder name --arch=x64 or 32-bit --electron-version version number (not your h5 version number, but the electron version number) --overwrite --ignore=node_modules

Packaging Example

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

refer to

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

This concludes this article about the steps to package the uniapp project as a desktop application. For more relevant uniapp project packaging content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • uniapp project optimization methods and suggestions
  • How to use mqtt in uniapp project
  • Based on vue+uniapp live broadcast project, uni-app imitates Douyin/Momo live broadcast room function
  • CentOS 7.2 builds nginx web server to deploy uniapp project

<<:  MySQL learning summary: a preliminary understanding of the architectural design of the InnoDB storage engine

>>:  When installing a virtual machine on Thinkpad VMware, the message "This host supports Intel VT-x, but Intel VT-x is disabled" appears (problem solution)

Recommend

Introduction to CSS style classification (basic knowledge)

Classification of CSS styles 1. Internal style --...

Vue implements countdown between specified dates

This article example shares the specific code of ...

js to achieve the pop-up effect

This article example shares the specific code of ...

Methods and steps for deploying GitLab environment based on Docker

Note: It is recommended that the virtual machine ...

How to view and optimize MySql indexes

MySQL supports hash and btree indexes. InnoDB and...

Summary of common docker commands

Docker installation 1. Requirements: Linux kernel...

Teach you how to use vscode to build a react-native development environment

question The code has no prompt: Many non-front-e...

js to achieve simple magnifying glass effects

This article example shares the specific code of ...

Use of MySQL triggers

Triggers can cause other SQL code to run before o...

Web Design: Script Materials Reconstruct User Experience

<br />Original text: http://blog.rexsong.com...

A brief discussion on why daemon off is used when running nginx in docker

I'm very happy. When encountering this proble...

Summary on Positioning in CSS

There are four types of positioning in CSS, which...

MySQL 8.0.11 MacOS 10.13 installation and configuration method graphic tutorial

The process of installing MySQL database and conf...

Summary of how to add root permissions to users in Linux

1. Add a user . First, use the adduser command to...

Analysis of the operating principle and implementation process of Docker Hub

Similar to the code hosting service provided by G...