1. Installation electron-packager
PS: Before installation, copy a package.json file to the ./app directory, and then change the path of "main": "app/main.js" in package.json in the ./app directory (remove app/) , if this is not the case, an error will be reported when the package is packaged below, and some versions cannot identify the application path.
1. Use the command npm install --save-dev electron-packager
to install the electron-package package under the project.
After the installation is complete, there will be an additional version number configuration information of the electron-package in the package.json file under the project root directory.
2. There are two methods for formal packaging
: 1. Directly use the command to package. The basic packaging commands of electron-packager are:
electron-packager <location of project> <name of project> <platform> <architecture> <electron version> <optional options>
- 1
Command description:
* location of project: the path where the project is located
* name of project: the name of the packaged project
* platform: determines which platform you want to build the application (Windows, Mac or Linux)
* architecture: determines whether to use x86 or x64 or both All architectures use
* electron version: the version of electron
* optional options: optional options
The command is relatively long, it will be very annoying to use this command to package every time, you can use the second method;
2. First add code to package.json under the project root directory, "packager": "electron-packager ./app HelloWorld --all --out ./OutApp --version 1.4.0 --overwrite --icon=./app/img/icon/icon.ico"
PS: It should be noted here that the project name, version, and icon path in the field should be changed to your own; the
specific addition location is as shown in the figure,
Then, after using the command npm run-script packager
最后,打包完成之后如图
运行对应包下的.exe文件,就可以看到我们的应用了。
转载自http://blog.csdn.net/arvin0/article/details/52690023
参数设置可参考下面,也是转载自某网友
- {
- "name": "hosts",
- "version": "2.0.1",
- "description": "",
- "main": "main.js",
- "scripts": {
- "start": "concurrently \"NODE_ENV=dev electron .\" \"webpack-dev-server --inline --hot --port 8080\"",
- "packageDarwin": "electron-packager . 'Hosts' --platform=darwin --arch=x64 --icon=hosts.icns --out=./dist --asar --app-version=2.0.1 --ignore=\"(dist|src|docs|.gitignore|LICENSE|README.md|webpack.config*|node_modules)\"",
- "packageWin": "electron-packager . 'Hosts' --platform=win32 --arch=x64 --icon=hosts.ico --out=./dist --asar --app-version=2.0.1 --ignore=\"(dist|src|docs|.gitignore|LICENSE|README.md|webpack.config.js|node_modules)\"",
- "packageLinux": "electron-packager . 'Hosts' --platform=linux --arch=x64 --out=./dist --asar --app-version=2.0.1 --ignore=\"(dist|src|docs|.gitignore|LICENSE|README.md|webpack.config.js|node_modules)\"",
- "prepackage": "rm -rf build && webpack --config webpack.config.prod.js && rm -rf dist",
- "package": "npm run packageDarwin && npm run packageWin && npm run packageLinux"
- },
- "author": "Howard.Zuo",
- "license": "MIT",
- "devDependencies": {
- "autoprefixer": "^6.7.6",
- "babel-core": "^6.23.1",
- "babel-loader": "^6.3.2",
- "babel-plugin-component": "^0.9.0",
- "babel-plugin-transform-object-rest-spread": "^6.23.0",
- "babel-plugin-transform-runtime": "^6.23.0",
- "babel-preset-es2015": "^6.22.0",
- "concurrently": "^3.4.0",
- "css-loader": "^0.26.2",
- "electron-packager": "^8.5.2",
- "electron-prebuilt": "^1.4.13",
- "file-loader": "^0.10.1",
- "html-webpack-plugin": "^2.28.0",
- "postcss-loader": "^1.3.3",
- "postcss-nested": "^1.0.0",
- "postcss-simple-vars": "^3.0.0",
- "style-loader": "^0.13.2",
- "vue-hot-reload-api": "^2.0.11",
- "vue-html-loader": "^1.2.4",
- "vue-loader": "^11.1.3",
- "vue-style-loader": "^2.0.3",
- "vue-template-compiler": "^2.2.1",
- "webpack": "^2.2.1",
- "webpack-dev-server": "^2.4.1"
- },
- "dependencies": {
- "element-ui": "^1.2.3",
- "hostile": "^1.3.0",
- "sudo-prompt": "^6.2.1",
- "vue": "^2.2.1"
- }
- }