1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
@echo off
:: 进入指定目录
cd dist
:: 在目录下创建package.json
(echo {
echo "name": "测试项目",
echo "version": "1.0.0",
echo "description": "",
echo "main": "main.js",
echo "scripts": {
echo "start": "electron ."
echo },
echo "author": "",
echo "license": "ISC",
echo "devDependencies": {
echo "electron": "^14.0.0"
echo }
echo }
) > package.json
:: 在目录下创建 main.js
echo //const {app,BrowserWindow} = require('electron'); 另一种引入写法 > main.js
echo const electron = require('electron'); >> main.js
echo const app = electron.app; >> main.js
echo const BrowserWindow = electron.BrowserWindow; >> main.js
echo const path = require('path'); >> main.js
echo const url = require('url'); >> main.js
echo let mainWindow; >> main.js
echo function createWindow() { >> main.js
echo // 创建一个窗口,大小 800 * 600 >> main.js
echo mainWindow = new BrowserWindow({ width: 800, height: 600 }); >> main.js
echo // 在窗口内要展示的内容为 ./dist/index.html,即打包生成的index.html >> main.js
echo //mainWindow.webContents.loadFile(__dirname+'./dist/index.html'); 另一种写法 >> main.js
echo mainWindow.loadURL(url.format({ >> main.js
echo pathname: path.join(__dirname,'index.html'), >> main.js
echo protocol: 'file:', >> main.js
echo slashes: true >> main.js
echo })); >> main.js
echo // 自动打开调试台 >> main.js
echo mainWindow.webContents.openDevTools({ detach: true }); >> main.js
echo mainWindow.on("closed", function () { >> main.js
echo mainWindow = null; >> main.js
echo }) >> main.js
echo } >> main.js
echo //启动应用加载 >> main.js
echo app.on('ready', createWindow); >> main.js
echo app.on('window-all-closed', function () { >> main.js
echo if (process.platform !== 'darwin') { >> main.js
echo app.quit(); >> main.js
echo } >> main.js
echo }) >> main.js
echo app.on('activate', function () { >> main.js
echo if (mainWindow === null) createWindow(); >> main.js
echo }); >> main.js
:: 提示用户操作完成
echo File moved successfully!
|