electron 安装到打包
1.下载安装node.js
2.安装electron。命令:npm install -g electron-prebuilt
3.安装打包模块。命令:npm install -g electron-packager
创建应用
创建3个文件:index.html,main.js,package.json
main.js
const {app, BrowserWindow} = require('electron') const path = require('path') const url = require('url') let win
//无边框全屏 function createWindow() { win = new BrowserWindow({frame: false,fullscreen:true}) win.loadURL(url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true })) //开发工具 //win.webContents.openDevTools() win.on('closed', () => { win = null }) } app.on('ready', createWindow) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) app.on('activate', () => { if (win === null) { createWindow() } })
package.json
{ "name": "npm", "version": "1.0.0", "description": "zhihu", "main": "main.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "electron ." }, "author": "yinian", "license": "ISC", "devDependencies": { "electron-packager": "^9.1.0", "electron-windows-inno-installer": "^0.1.3", "grunt": "^1.0.1", "grunt-electron-installer": "^2.1.0" } }
打包命令:
electron-packager <应用目录> <应用名称> <打包平台> --out <输出目录> <架构> <应用版本>
electron-packager . shineeArt --win --out ../shineeArtiExe --arch=ia32 --version=1.0.0 --electron-version=1.4.13 (--overwrite --ignore=node_modules)
electron 触摸屏禁止缩放代码(可行性?)
require('electron').webFrame.setZoomLevelLimits(1,1)