Summary of questions about electron

Note:
The problem occurs in the following versions
node: v16.20.1
vue: ^3.2.13
electron: ^25.3.1
electron-builder: ^2.1.1

1. The problem of electron-builder packaging being slow and causing errors

Due to network reasons, you may have to wait for a long time when packaging the builder, and it will eventually fail.
If it is the first time to package the builder, you will download winCodeSign, nsis, nsis-resourcesand often get stuck at the first one.
Solution:
When downloading the above three resource packages, the corresponding addresses will be printed on the console. We can copy the addresses and download them manually, or we can find the https://github.com/electron-userland/electron-builder-binaries/releasescorresponding resources by ourselves. You can use some download software to download faster. some, and then put them C:\Users\这个是你当前的电脑用户文件夹\AppData\Local\electron-builder\Cachedown (the appdata folder cannot be found in the user folder, you need to manually add it after the address bar \appdata). Note that the storage path format is as follows (the version number may be different)

C:\Users\This is your current computer user folder\AppData\Local\electron-builder
|--- Cache
| |--- winCodeSign
| | |--- winCodeSign-2.6.0
| |--- nsis
| | |--- nsis-3.0.5.0
| | |--- nsis-resources-3.4.1

Then we can repackage it

2. The ui icon is not displayed after packaging

If you use UI frameworks such as elementui, they will become frames after packaging (▯)
Solution: add in
vue.config.jspluginOptionselectronBuilder

customFileProtocol: './'

3. There is a problem that the module cannot be found after electron-builder.

After electron-builder is packaged, it may appear

Could not find module root given file: "app://./js/xx.js"

I have never encountered this before. I don’t know if it is a version problem. It is said that there is an official explanation.

Native modules are supported and should work without any configuration, assuming nodeIntegration is enabled. If you get errors, you may need to set the native dependency as an webpack external (opens new window). It should get found automatically, but it might not. To do this, use the externals option

Then, I looked under dist_electron\bundled and package.jsonfound that there were no dependencies, only devDependencies.
So, I added a configuration in vue.config.js, followed by nodeIntegration: true:

externals: [
    "core-js",
    "view-ui-plus",
    "vue",
   	"...这里是你的依赖"
]

This will keep the dependencies you want to keep

------ I will add more when I meet others later...

Guess you like

Origin blog.csdn.net/jl15988/article/details/131926922