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

Several ways to schedule backup of MySQL database (comprehensive)

Table of contents 1. mysqldump command to back up...

How to make your JavaScript functions more elegant

Table of contents Object parameters using destruc...

Detailed basic operations on data tables in MySQL database

Table of contents 1. View the tables in the curre...

Use the CSS border-radius property to set the arc

Phenomenon: Change the div into a circle, ellipse...

Detailed explanation of the setting of background-image attribute in HTML

When it comes to pictures, the first thing we thi...

Summary of Common Terms in CSS (Cascading Style Sheet)

If you use CSS don't forget to write DOCTYPE, ...

Three ways to communicate between React components (simple and easy to use)

Table of contents 1. Parent-child component commu...

Use of Linux bzip2 command

1. Command Introduction bzip2 is used to compress...

Analysis and solution of data loss during Vue component value transfer

Preface In the previous article Two data types in...

MySQL kill command usage guide

KILL [CONNECTION | QUERY] processlist_id In MySQL...

Install Memcached and PHP Memcached extension under CentOS

Regarding the high-performance distributed memory...

CSS Paint API: A CSS-like Drawing Board

1. Use Canvas images as CSS background images The...

Solution to index failure in MySQL due to different field character sets

What is an index? Why create an index? Indexes ar...