第一步:node.js
第二步:进入工作目录app npm init
第三步:npm install --save-dev electron-prebuilt || npm install electron-prebuilt -g 全局安装
第四步:npm install electron 或者直接将electron解压包放入node工作目录
第五步:electron.exe .
npm install electron
或者直接将electron解压包放入node工作目录
npm install **
需要到app目录中去
进入app目录
注意:目录中必须含有node_modules文件夹
npm run-script packager
"packager": "electron-packager . firstProject --all --out . --version 1.4.13 --overwrite --icon=logo.ico"
{
"name": "app",
"version": "1.4.13",
"main": "main.js",
"devDependencies": {
"electron-packager": "^8.7.0"
},
"scripts": {
"test": "start",
"start": "electron .",
"packager": "electron-packager . firstProject --Windows --x64 . --version 1.4.13 --overwrite --icon=logo.ico"
}
}
"packager": "electron-packager . weiyu --all --out . --version 1.4.13 --overwrite --icon=logo.ico"
{
"name": "weiyu",
"version": "1.0.0",
"description": "this is my project",
"main": "main.js",
"devDependencies": {
"electron-packager": "^8.7.0",
"grunt-electron-installer": "^2.1.0"
},
"scripts": {
"test": "start",
"start": "electron .",
"packager": "electron-packager . weiyu --Windows --out . --version 1.4.13 --overwrite --icon=./public/img/logo.ico"
}
}
打包成单独exe,所有操作都是在app目录下 (http://www.tuicool.com/articles/ABB3eiu)
第一步:先打包好 ---->>>> npm run-script packager
第二步:安装grunt-electron-installer ---->>>> npm install grunt-electron-installer --save-dev
第三步:安装grunt ---->>>> npm install grunt --save-dev
---->>>> npm install -g grunt-cli
---->>>> npm install -g grunt (grunt -version)
第四步:配置Gruntfile.js ---->>>>
第五步:成快捷方式,在main.js里加入如下:
var handleStartupEvent = function () {
if (process.platform !== 'win32') {
return false;
}
var squirrelCommand = process.argv[1];
switch (squirrelCommand) {
case '--squirrel-install':
case '--squirrel-updated':
install();
return true;
case '--squirrel-uninstall':
uninstall();
app.quit();
return true;
case '--squirrel-obsolete':
app.quit();
return true;
}
// 安装
function install() {
var cp = require('child_process');
var updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'update.exe');
var target = path.basename(process.execPath);
var child = cp.spawn(updateDotExe, ["--createShortcut", target], { detached: true });
child.on('close', function(code) {
app.quit();
});
}
// 卸载
function uninstall() {
var cp = require('child_process');
var updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'update.exe');
var target = path.basename(process.execPath);
var child = cp.spawn(updateDotExe, ["--removeShortcut", target], { detached: true });
child.on('close', function(code) {
app.quit();
});
}
};
if (handleStartupEvent()) {
return;
}
第六步:生成快捷方式的名字 "packager": "electron-packager . weiyu --Windows --out . --version 1.4.13 --overwrite --icon=./public/img/logo.ico --version-string.CompanyName=weiyu --version-string.ProductName=weiyu"
第七步:grunt