Menu
Electron - Create Single App for Windows, Linux, and macOS article
You might be asking why do we have two targets for mac (zip and dmg). To clarify, the zip file is required by autoUpdater while the dmg file would be distributed to our end users. Code signing. Further, code signing on macOS is very simple as electron-builder automatically picks. Api documentation for electron-builder (v17.0.1) A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out of the box. Dec 30, 2016 Packaging an electron app simply means creating a desktop installer (dmg, exe, deb etc). Now if you decide to go around manually packaging your app, you’re gonna have a. A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box. Appimage appx auto-update builder deb distribution-electron dmg electron electron-builder electron-updater linux macos muon nsis pkg rpm snap squirrel.mac.zip: required for Squirrel.Mac. See the Auto Update. A complete solution to package and build a ready for distribution Electron, Proton Native app for macOS, Windows and Linux with “auto update” support out of the box. See documentation on electron.build. NPM packages management: Native application dependencies compilation (including Yarn support).; Development dependencies are never included. You might be asking why do we have two targets for mac (zip and dmg). To clarify, the zip file is required by autoUpdater while the dmg file would be distributed to our end users. Code signing. Further, code signing on macOS is very simple as electron-builder automatically picks the right identity from your keychain.
electronBuilder.js
constpackagejson=require('../package.json'); |
constbuilder=require('electron-builder'); |
constmimes=newMap(); |
mimes.set('exe','exe'); |
mimes.set('dmg','dmg'); |
mimes.set('zip','zip'); |
mimes.set('AppImage','x-executable'); |
//Development package.json, see https://goo.gl/5jVxoO |
constdevMetadata=packagejson.electronBuilder; |
//Application package.json |
constappMetadata={ |
name: packagejson.name, |
version: packagejson.version, |
description: packagejson.description, |
author: packagejson.author |
}; |
functionbuildPromise(){ |
returnnewPromise((resolve,reject)=>{ |
builder |
.build({projectDir: './', devMetadata, appMetadata }) |
.then(args=>{ |
constfilePath=args[0]; |
constfileName=filePath.substr(filePath.replace(//g,'/').lastIndexOf('/')+1); |
constext=fileName.substr(fileName.lastIndexOf('.')+1); |
letmimeType; |
if(mimes.has(ext)) |
mimeType=`application/${mimes.get(ext)}, application/octet-stream`; |
else |
console.warn(`Unsupported file type '${ext}' in file '${filePath}'; mime type will be null`); |
resolve({fileName, filePath, mimeType}); |
}).catch((error)=>{ |
console.error(error); |
}); |
}); |
} |
module.exports=buildPromise; |
electronBuilder.json
'electronBuilder': { |
'build': { |
'productName': 'Node Performance Measure', |
'appId': 'EikosPartners.NodePerformanceMeasure', |
'asar': false, |
'win': { |
'iconUrl': 'http://localhost:5000/images/eikos-logo-multi.ico', |
'target': 'nsis' |
}, |
'nsis': { |
'oneClick': false, |
'allowElevation': false |
}, |
'linux': { |
'target': 'AppImage', |
'category': 'Development' |
}, |
'mac': { |
'target': 'dmg' |
} |
}, |
'directories': { |
'output': 'electron/output', |
'app': 'electron/app', |
'buildResources': 'electron/buildResources' |
} |
} |
electronInstall.html
<div> |
<inputtype='button' value='Electron' onclick='downloadElectron();' /> |
<spanid='spanElectron'>Build Electron Version Installer for detected OS:</span> |
</div> |
<scripttype='text/javascript'> |
varosdetect='UNKNOWN!'; |
varplatform=navigator.platform.toLowerCase(); |
if(platform.indexOf('win') >= 0) |
osdetect='Windows'; |
elseif(platform.indexOf('mac') >= 0) |
osdetect='MacOS'; |
elseif(platform.indexOf('linux') >= 0) |
osdetect='Linux'; |
document.getElementById('spanElectron').innerHTML+=' <i><strong>'+osdetect+'</strong></i>'; |
functiondownloadElectron(){ |
varhostname=location.hostname; |
varport=location.port.length>0 ? ':'+location.port : '; |
varurl='http://'+hostname+port+'/electron' |
window.open(url); |
} |
</script> |
electronRoute.js
//Install page for Electron Application |
router.get('/electron',function(req,res,next){ |
electronBuilder() |
.then(e=>fs.readFile(e.filePath,(err,data)=>{ |
res.setHeader('Content-Disposition',`attachment; filename='${e.fileName}'`); |
res.setHeader('Content-type',e.mimeType); |
res.send(data); |
})).catch((error)=>{ |
console.error(error); |
}); |
}); |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Electron-builder Mac Target Zip Dmg Code
- 'name':'VRIGateway',
- 'license':'MIT',
- 'description':'VRI Gateway Application',
- 'dev':'electron-webpack dev',
- 'dist':'yarn compile && electron-builder',
- 'dist-win32':'yarn run dist -w --ia32',
- 'dist-linux32':'yarn run dist -l --ia32',
- 'dist-win':'yarn run dist-win32 && yarn run dist-win64',
- 'dist:dir':'yarn dist --dir -c.compression=store -c.mac.identity=null'
- 'dependencies':{
- 'electron-dl':'^1.10.0',
- 'electron-to-chromium':'^1.3.27',
- 'node-notifier':'^5.2.1',
- },
- 'electron':'2.0.0',
- 'electron-webpack':'^2.0.1',
- },
- 'publish':[
- 'provider':'generic',
- }
- 'nsis':{
- 'allowElevation':true
- 'win':{
- {
- 'arch':[
- 'ia32'
- }
- },
- 'category':'public.app-category.business',
- 'zip',
- ]
- }