electron是基于nodejs使用 JavaScript,HTML 和 CSS 构建跨平台的桌面应用程序
命令:npm install -g electron
使用electron --version 可以查询electron版本,因为打包使用的是electron–builder,所以electron包需要使用7.0.0以上的版本
cnpm install -g electron-prebuilt
cnpm install -g electron-packager
cnpm install electron-builder -g
打包命令有两个electron-packager 和 electron-builder,经过网上查询资源,自己只使用了electron-builder,具体区别可以去搜索
cnpm install -g asar
新建项目文件夹,进入项目文件夹,进入cmd,运行npm init
初始化完成后会生成package.json,里面新增electron的依赖,否则最终无法打包
“devDependencies”: {
“electron”: “10.1.4”
}
index.html文件:
shawemouDemo
请输入
index.js文件:
const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')
let window = null
// Wait until the app is ready
app.once('ready', () => {
// Create a new window
window = new BrowserWindow({
// Set the initial width to 800px
width: 800,
// Set the initial height to 600px
height: 600,
// Set the default background color of the window to match the CSS
// background color of the page, this prevents any white flickering
backgroundColor: "#D6D8DC",
// Don't show the window until it's ready, this prevents any white flickering
show: false
})
// Load a URL in the window to the local index.html path
window.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
// Show window when page is ready
window.once('ready-to-show', () => {
window.show()
})
})
运行:" electron-builder --win —x64 "
https://github.com/shawemou/electron_simpleDemo
git clone https://github.com/shawemou/electron_simpleDemo
cd electron_simpleDemo
npm install
electron .
关于vue-cli的技术不在这里讲解
修改index.js文件,将引用的index.html修改为./qhconfig/index.html
window.loadURL(url.format({
pathname: path.join(__dirname, './qhconfig/index.html'),
protocol: 'file:',
slashes: true
}))