Electron packs and generates exe files

Packing method 1: DOS window command packing

Under DOS, enter npm install electron-packager -g to install our packaging artifact globally :

cnpm install electron-packager -g

Under the project folder, that is, under the root directory, open DOS to execute the packaging command:

electron-packager . HelloWorld --platform=win32 --arch=x64 --icon=computer.ico --out=./out --asar --app-version=0.0.1 --overwrite --ignore=node_modules --electron-version 5.0.0

Introduction to each parameter:

HelloWorld :你将要生成的exe文件的名称
--platform=win32: Determine which platform application you want to build, the possible values ​​are darwin,  linuxmaswin32
--arch=x64:决定了使用 x86 还是 x64 还是两个架构都用
--icon=computer.ico:自定义设置应用图标
--out=./out: Specify the folder location of the package file output, currently specified as the out folder in the project directory
--asar:该参数可以不加,如果加上,打包之后应用的源码会以.asar格式存在,否则会以文件夹形式存在
--app-version=0.0.1:生成应用的版本号
--overwrite: Overwrite the original build, let the newly generated package overwrite the original package
--ignore=node_modules:如果加上该参数,项目里node_modules模块不会被打包进去
--electron-version 5.0.0: Specify the current version of electron to be built. It needs to be consistent with the current version. You can check it in the package.json file for details. You can not add this parameter. If it is inconsistent, it will be downloaded automatically. Not recommended

Packaging method 2: package.json setting packaging:

It is recommended to set the packaged commands in package.jsonthescript

The settings are as follows:

  "scripts": {"package":"electron-packager . HelloWorld --platform=win32 --arch=x64 --icon=computer.ico --out=./out --asar --app-version=0.0.1 --overwrite --ignore=node_modules"
  }

Then execute the command under the project folder DOS window:

npm run package

can be packaged successfully

Guess you like

Origin blog.csdn.net/q907811175/article/details/108865706