原文地址:https://blog.csdn.net/a1170201028/article/details/59108126
一、安装electron-packager
PS:安装之前,先复制一份package.json文件到./app目录下,然后改下./app目录下package.json里 “main”: “app/main.js”的路径(去掉app/),不这样子的话,下面打包的时候会报错,有的版本识别不了应用路径。
1、使用命令npm install --save-dev electron-packager
将electron-package包安装到在项目下面,
安装完成之后,项目根目录下面的package.json文件里,会多出一条electron-package的版本号配置信息
二、正式打包
有两种方法:
1、直接使用命令打包,electron-packager的打包基本命令是:
electron-packager <location @H_502_31@of @H_502_31@project> <name platform> <architecture> <electron @H_502_31@version> <optional @H_502_31@options>
- 1
命令说明:
* location of project:项目所在路径
* name of project:打包的项目名字
* platform:确定了你要构建哪个平台的应用(Windows、Mac 还是 Linux)
* architecture:决定了使用 x86 还是 x64 还是两个架构都用
* electron version:electron 的版本
* optional options:可选选项
命令比较长,每次要是都用这个命令来打包会很烦,可以使用第二种方法;
2、首先在项目根目录下面的 package.json 里添加代码,"packager": "electron-packager ./app HelloWorld --all --out ./OutApp --version 1.4.0 --overwrite --icon=./app/img/icon/icon.ico"
PS:这里要注意,字段里的 项目名字,version,icon路径要改成自己的;
具体添加位置如图,
然后,在使用命令npm run-script packager
最后,打包完成之后如图
运行对应包下的.exe文件,就可以看到我们的应用了。
转载自http://blog.csdn.net/arvin0/article/details/52690023
参数设置可参考下面,也是转载自某网友
- {
- "name":"hosts",
- "version":"2.0.1",
- "description":"",108);color:inherit;line-height:18px;list-style-position:outside;">"main":"main.js",248);line-height:18px;list-style-position:outside;">"scripts":{
- "start":"concurrently\"NODE_ENV=develectron.\"\"webpack-dev-server--inline--hot--port8080\"",
- "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)\"",248);line-height:18px;list-style-position:outside;">"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)\"",108);color:inherit;line-height:18px;list-style-position:outside;">"prepackage":"rm-rfbuild&&webpack--configwebpack.config.prod.js&&rm-rfdist",248);line-height:18px;list-style-position:outside;">"package":"npmrunpackageDarwin&&npmrunpackageWin&&npmrunpackageLinux"
- },248);line-height:18px;list-style-position:outside;">"author":"Howard.Zuo",108);color:inherit;line-height:18px;list-style-position:outside;">"license":"MIT",248);line-height:18px;list-style-position:outside;">"devDependencies":{
- "autoprefixer":"^6.7.6",248);line-height:18px;list-style-position:outside;">"babel-core":"^6.23.1",108);color:inherit;line-height:18px;list-style-position:outside;">"babel-loader":"^6.3.2",248);line-height:18px;list-style-position:outside;">"babel-plugin-component":"^0.9.0",108);color:inherit;line-height:18px;list-style-position:outside;">"babel-plugin-transform-object-rest-spread":"^6.23.0",248);line-height:18px;list-style-position:outside;">"babel-plugin-transform-runtime":"^6.23.0",108);color:inherit;line-height:18px;list-style-position:outside;">"babel-preset-es2015":"^6.22.0",248);line-height:18px;list-style-position:outside;">"concurrently":"^3.4.0",108);color:inherit;line-height:18px;list-style-position:outside;">"css-loader":"^0.26.2",248);line-height:18px;list-style-position:outside;">"electron-packager":"^8.5.2",108);color:inherit;line-height:18px;list-style-position:outside;">"electron-prebuilt":"^1.4.13",248);line-height:18px;list-style-position:outside;">"file-loader":"^0.10.1",108);color:inherit;line-height:18px;list-style-position:outside;">"html-webpack-plugin":"^2.28.0",248);line-height:18px;list-style-position:outside;">"postcss-loader":"^1.3.3",108);color:inherit;line-height:18px;list-style-position:outside;">"postcss-nested":"^1.0.0",248);line-height:18px;list-style-position:outside;">"postcss-simple-vars":"^3.0.0",108);color:inherit;line-height:18px;list-style-position:outside;">"style-loader":"^0.13.2",248);line-height:18px;list-style-position:outside;">"vue-hot-reload-api":"^2.0.11",108);color:inherit;line-height:18px;list-style-position:outside;">"vue-html-loader":"^1.2.4",248);line-height:18px;list-style-position:outside;">"vue-loader":"^11.1.3",108);color:inherit;line-height:18px;list-style-position:outside;">"vue-style-loader":"^2.0.3",248);line-height:18px;list-style-position:outside;">"vue-template-compiler":"^2.2.1",108);color:inherit;line-height:18px;list-style-position:outside;">"webpack":"^2.2.1",248);line-height:18px;list-style-position:outside;">"webpack-dev-server":"^2.4.1"
- "dependencies":{
- "element-ui":"^1.2.3",248);line-height:18px;list-style-position:outside;">"hostile":"^1.3.0",108);color:inherit;line-height:18px;list-style-position:outside;">"sudo-prompt":"^6.2.1",248);line-height:18px;list-style-position:outside;">"vue":"^2.2.1"
- }
- }