The company’s computer cannot access the external network, and when installing electron from the company’s self-built NPM warehouse, errors have been reported all the time. You can only try an offline installation

Operating train of thought

  1. Download the Electron compression package in advance.
  2. If the Electron download is slow or a timeout error occurs, the installation process is interrupted.
  3. Modify the Electron installation script to remove the download process and decompress the downloaded compressed package.
  4. Run the installation script for Electron to complete the installation.

Preparations:

  1. Install the Node environment (Version 10 or later)
  2. Download the electron v12.0.7 version Windows version zip: electron-v12.0.7-win32-x64.zip MAC version zip: electron- v12.0.7-Darwin x64.zip

Specific methods are as follows: 2. Open the demo_ELEc folder in terminal and type NPM init to initialize a package.json file. 3 Electron, when the execution is about to complete (timing is not easy), the CTR + C termination procedure is executed. The interface is as follows:

4. Find node_modules>electron>install.js and make the following changes

5. Place the electron-v12.0.7-win32-x64.zip package into the electron directory

6. Open the electron folder in the terminal, enter the command node install.js, and run the install.js file to generate the dist folder. As shown in the figure:

7. Configure commands and dependencies in package.json as follows:

{" name ":" demo_elec ", "version" : "1.0.0", "description" : ""," main ":". The main js ", "scripts" : {" test ", "echo \" Error: no test specified\" && exit 1", "start": "electron ." }, "author": "paodan", "license": "ISC", "dependencies": { "electron": "*" } }Copy the code

8, index.html page, code as follows:

<! DOCTYPE HTML >< HTML >< head> <meta charset="UTF-8"> <title></title> </head> <body> This is my first electron demo! </body> </html>Copy the code

9. Main. js file with the following code:

const {app,BrowserWindow} = require('electron');
 
function createWindow () {
  const win = new BrowserWindow({
    width: 800,
    height: 600
  })

  win.loadFile('index.html')
}
app.whenReady().then(() => {
  createWindow()
})

Copy the code

10. Run NPM run start on the terminal

11. The running results are shown in figure

See link Electron offline installation Electron document Electron FAQs