How to quickly package a website into a win desktop application? How to package a webpage as a windows desktop application? Use Electron to package web pages into win desktop applications

Install the necessary software:

First you need to install Node.js and Electron. You can download and install them by visiting the following websites:

Node.js: https://nodejs.org/en/
Electron: https://www.electronjs.org/

Create your application:

On your computer, create a new folder as your project directory and inside it create an HTML file (eg: index.html) containing the website content you want to package. If you want the application to open a certain url:

win.loadURL('https://example.com')

Create a main.js file:

Create a main.js file in your project directory, and write the entry code of Electron to create a window. Here is a simple sample code:

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

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

  const myUrl = 'https://www.baidu.com/'
  win.loadURL(encodeURI(myUrl))
  win.webContents.openDevTools()
}

app.whenReady().then(() => {
    
    
  createWindow()
})

Package the application:

Enter the project directory. Use the command line to run the following command to package the application:

npm install -g electron-packager
electron-packager . myApp --platform=win32 --arch=x64 --electron-version:8.2.1

This command will be packaged as myApp.exe file and run on Windows.

Through the above simple steps, you can quickly package the website as a Win desktop application, and use Atom, VS Code or other corresponding text editors to edit and debug your application.

Guess you like

Origin blog.csdn.net/gjwgjw1111/article/details/130508471