1. Instale node.js Por ejemplo: instale bajo F: // nodo;
2. consola cmd:
F:
Presione Enter, ingrese F drive,
cd node
Presione Enter, ingrese a la carpeta del nodo,
node -v
Presione Entrar para ver la versión del nodo,
npm -v
Presione Enter para verificar la versión npm, si aparece el número de versión, significa que la instalación fue exitosa;
3. En la consola cmd, debajo de la carpeta del nodo, cambie el almacén de npm al almacén de taobao doméstico. La velocidad será mucho más rápida. El comando es el siguiente:
npm install -g cnpm --registry=https://registry.npm.taobao.org
4. En la carpeta del nodo, instale electron, el comando es el siguiente:
cnpm install -g electron
5. Ingrese el comando:
electron -v
Verifique la versión electrónica, si aparece el número de versión, significa que la instalación fue exitosa;
6. Ingrese el comando:
cnpm install -g electron-packager
Herramienta de salida de paquetes;
7. Descargue e instale el cliente electron;
8. Cree una nueva carpeta de proyecto y asígnele un nombre, por ejemplo: test1;
9. Cree tres archivos en test1: pakage.json, index.html y main.js;
10. Arrastre y suelte la carpeta test1 al cliente de electron, o use un comando en la consola cmd para abrir el archivo,
F:\electron1\electron.exe E:\electronCodes\test1
La parte delantera es la dirección del cliente y la parte trasera es la dirección del archivo.
Apéndice: pakage.json, index.html, main.js
pakage.json:
{
"name" : "your-app",
"version" : "0.1.0",
"main" : "main.js"
}
index.html :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
We are using node <script>document.write(process.versions.node)</script>,
Chrome <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
</body>
</html>
main.js:
const electron = require('electron');
// Module to control application life.
const {
app} = electron;
// Module to create native browser window.
const {
BrowserWindow} = electron;
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 800, height: 600});
// and load the index.html of the app.
win.loadURL(`file://${
__dirname}/index.html`);
// Open the DevTools.
win.webContents.openDevTools();
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow();
}
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.