Method 1: Clone the electron project for packaging

  • Step 1: Clone the ELECTRON project and run it

    1, 2, CD electron git clone https://github.com/electron/electron-quick-start - quick - start 3, NPM install 4, NPM start / / Starting the project will open electronCopy the code
  • Step 2: Package your application

    1. Pack the VUE project first: NPM run build, and place the generated dist file in the root directory of the ELECTRON project

    2. Change the path of the load file in main.js in the electron project directory

    Mainwindow.loadfile ('index.html') // Default request path mainwindow.loadfile ('./dist/index.html') // modified: Replace the file path with index.html in the packaged dist directoryCopy the code

    3. NPM I: install the dependency, NPM run start: start the program, the electron application opens, if the page displays normally, there is no problem, then install the dependency and pack it

    4, Install the electron, electron packager dependency:

        npm install electron --save-dev
        npm install electron-packager --save-dev
    Copy the code

    5. Configure the packaging command in package.json file

    "Package ":" electric-packager. electron desktop application --win --out.. / electron desktop applications - electron - version 6.0.7 - overwrite - icon. = / dist/static/img/logo ico - platform win32 --ignore=node_modules"Copy the code

    6. Run NPM Run Package to package

    WARNING: Make sure that.net Framework 4.5 or later and Powershell 3 or later are installed, otherwise extracting the Electron zip file will hang. This means that NET Framework must be 4.5 or later and Powershell must be 3.0 or later to be packaged successfullyCopy the code

Mode 2: VUE combined with electron packing

1. Copy the main.js file in the electron project to the root directory of the vue project and rename it as.electron.js

const {app, BrowserWindow} = require('electron') const path = require('path') let mainWindow function createWindow () { mainWindow = New BrowserWindow({width: 500, // window width height: 1200, // window height webPreferences: {preload: Path.join (__dirname, 'preload.js')}}) mainwindow.loadFile ('./dist/index.html') mainwindow.on ('closed', function () { mainWindow = null }) } app.on('ready', createWindow) app.on('window-all-closed', function () { if (process.platform ! == 'darwin') app.quit() }) app.on('activate', function () { if (mainWindow === null) createWindow() })Copy the code

Install the electron, electron packager dependency:

    npm install electron --save-dev
    npm install electron-packager --save-dev
Copy the code

3. Configure the command in package.json and import.electron

"Electron_dev ":" NPM run build && electron.electron. js", "package": "electron-packager. electron desktop application --win --out.. /.. / electron desktop applications - electron - version 6.0.7 - overwrite - icon. = / dist/static/img/logo ico - platform win32 --ignore=node_modules"Copy the code

4, packaging,

NPM run package NPM run package // electron packCopy the code