Electron Windows Installer 使用教程

Electron Windows Installer 使用教程

windows-installerBuild Windows Installers for Electron apps项目地址:https://gitcode.com/gh_mirrors/wi/windows-installer

1. 项目的目录结构及介绍

Electron Windows Installer 项目的目录结构如下:

/
├── .github/
│   └── workflows/
├── scripts/
├── src/
│   ├── main/
│   └── renderer/
├── .gitignore
├── .npmrc
├── package.json
├── README.md
└── tsconfig.json

目录介绍

  • .github/workflows/: 包含 GitHub Actions 的工作流配置文件。
  • scripts/: 包含项目使用的脚本文件。
  • src/: 项目的源代码目录,包含 mainrenderer 两个子目录。
    • main/: 主进程的源代码。
    • renderer/: 渲染进程的源代码。
  • .gitignore: Git 忽略文件配置。
  • .npmrc: npm 配置文件。
  • package.json: 项目的 npm 配置文件,包含依赖、脚本等信息。
  • README.md: 项目说明文档。
  • tsconfig.json: TypeScript 配置文件。

2. 项目的启动文件介绍

项目的启动文件位于 src/main/ 目录下,通常是 index.tsmain.ts。这个文件负责启动 Electron 应用的主进程。

// src/main/index.ts
import { app, BrowserWindow } from 'electron';

function createWindow() {
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
    },
  });

  mainWindow.loadFile('index.html');
}

app.whenReady().then(createWindow);

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});

3. 项目的配置文件介绍

package.json

package.json 文件包含了项目的元数据和依赖信息。以下是一些关键字段:

{
  "name": "electron-windows-installer",
  "version": "1.0.0",
  "main": "src/main/index.ts",
  "scripts": {
    "start": "electron .",
    "build": "tsc",
    "package": "electron-builder"
  },
  "dependencies": {
    "electron": "^13.1.7"
  },
  "devDependencies": {
    "typescript": "^4.3.5",
    "electron-builder": "^22.11.7"
  }
}

tsconfig.json

tsconfig.json 文件是 TypeScript 的配置文件,用于配置 TypeScript 编译选项。

{
  "compilerOptions": {
    "target": "ES2017",
    "module": "commonjs",
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "esModuleInterop": true
  },
  "include": ["src/**/*"]
}

通过以上配置,可以确保项目能够正确编译和运行。

windows-installerBuild Windows Installers for Electron apps项目地址:https://gitcode.com/gh_mirrors/wi/windows-installer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

窦岑品

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值