electron 安装
安装步骤
-
npm install -g cnpm --registry=https://registry.npm.taobao.org
-
创建后,在vscode里面创建一个新的空文件夹,打开你的命令行工具,然后从该文件夹运行npm init
-
npm 会帮助你创建一个基本的 package.json 文件。 其中的 main 字段所表示的脚本为应用的启动脚本,它将会在主进程中执行,在scripts中,添加start:"electron .“注意有个空格在.前
-
安装方法是把它作为您 app 中的开发依赖项,这使您可以在不同的 app 中使用不同的 Electron 版本。 在您的app所在文件夹中运行下面的命令:
npm install --save-dev electron
-
创建个js文件,输入例子:
const { app, BrowserWindow } = require('electron')
function createWindow () { // 创建浏览器窗口 let win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true } })
// 加载index.html文件 win.loadFile('index.html')
}
app.on('ready', createWindow)
-
建一个html文件就可以在其中写样式了,命令运行 npm start
-