Skip to content

Commit d7c7954

Browse files
committed
feat: update Hero, Features
1 parent 8a33028 commit d7c7954

9 files changed

+138
-381
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ yarn.lock
1212

1313
# dist
1414
cache
15+
logs
16+
temp

.vitepress/config.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,9 @@ export default defineConfig({
4242
items: [
4343
{ text: 'Why Electron⚡️Vite', link: '/guide/why-electron-vite' },
4444
{ text: 'Getting Started', link: '/guide/getting-started' },
45-
]
46-
},
47-
{
48-
text: 'Plugin',
49-
collapsed: false,
50-
items: [
51-
{ text: 'Vite Plugin Electron', link: '/plugin/vite-plugin-electron' },
52-
{ text: 'Vite Plugin Electron-renderer', link: '/plugin/vite-plugin-electron-renderer' },
45+
{ text: 'Features', link: '/guide/features' },
46+
{ text: 'Plugins', link: '/guide/plugins' },
47+
{ text: 'Templates', link: '/guide/templates' },
5348
]
5449
},
5550
{

guide/features.md

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Features
2+
3+
All Electron⚡️Vite features are included in a [vite-plugin-electron](/guide/plugins.html#vite-plugin-electron) plugin based on Vite, which makes it easy for users to quickly integrate Electron in a Vite project.
4+
5+
<details>
6+
<summary>中文</summary>
7+
<p>Electron⚡️Vite 所有功能均包含在一个基于 Vite 开发的 <a href="/guide/plugins.html#vite-plugin-electron">vite-plugin-electron</a> 插件,它能使得用户能很方便的在一个 Vite 项目中快速集成 Electron。</p>
8+
</details>
9+
10+
## HOT Restart
11+
12+
By default [vite-plugin-electron](/guide/plugins.html#vite-plugin-electron) has automatic restart enabled, which works simply by listening for the completion of a Vite build that kills the running Electron App process and restarts a new Electron App process.
13+
14+
However, you can control the default behavior however you like.
15+
16+
<details>
17+
<summary>中文</summary>
18+
<p>默认情况下 <a href="/guide/plugins.html#vite-plugin-electron">vite-plugin-electron</a> 开启了自动重启,它的工作原理仅仅是监听 Vite 构建完成后杀死正在运行的 Electron App 进程,然后重启一个新的Electron App 进程。</p>
19+
<p>不过你可以随意控制默认行为。</p>
20+
</details>
21+
22+
23+
```ts
24+
// vite.config.ts
25+
import electron from 'vite-plugin-electron'
26+
27+
export default {
28+
plugins: [
29+
electron({
30+
// Main process entry file of the Electron App.
31+
entry: 'electron/main.ts',
32+
// If this `onstart` is passed, Electron App will not start automatically.
33+
// However, you can start Electroo App via `startup` function.
34+
onstart(args) {
35+
args.startup()
36+
},
37+
}),
38+
],
39+
}
40+
```
41+
42+
## HMR
43+
44+
HMR i.e. the Renderer process hot replaces modified parts of the code when they are modified, and HMR is a great development experience! It is based on [Vite's built-in HMR](https://vitejs.dev/guide/features.html#hot-module-replacement), which is enabled by the Main process during development via the `process.env.VITE_DEV_SERVER_URL` environment variable.
45+
46+
<details>
47+
<summary>中文</summary>
48+
<p>HMR 即渲染进程修改代码后会热替换修改的部分,HMR 的开发体验非常棒!它基于 <a href="https://vitejs.dev/guide/features.html#hot-module-replacement">Vite 内置的 HMR</a>,在开发期间主进程通过 <code>process.env.VITE_DEV_SERVER_URL</code> 环境变量开启它。</p>
49+
</details>
50+
51+
52+
```ts
53+
// electron/main.ts
54+
import { app, BrowserWindow } from 'electron'
55+
56+
app.whenReady().then(() => {
57+
const win = new BrowserWindow({
58+
title: 'Main window',
59+
})
60+
61+
// You can use `process.env.VITE_DEV_SERVER_URL` when the vite command is called `serve`
62+
if (process.env.VITE_DEV_SERVER_URL) {
63+
win.loadURL(process.env.VITE_DEV_SERVER_URL)
64+
} else {
65+
// Load your file
66+
win.loadFile('dist/index.html');
67+
}
68+
})
69+
```
70+
71+
## HOT Reload
72+
73+
When Preload scripts is modified, we just need to refresh the Renderer process. But it requires us to control it explicitly because Vite doesn't know which code is the Preload scripts. It's really simple!
74+
75+
<details>
76+
<summary>中文</summary>
77+
<p>当预加载脚本被修改时,我们只需要重新刷新渲染进程就可以了,但是它需要我们显式的控制它,因为 Vite 不知道哪些代码是预加载脚本。它很简单!</p>
78+
</details>
79+
80+
```ts
81+
// vite.config.ts
82+
import electron from 'vite-plugin-electron'
83+
84+
export default {
85+
plugins: [
86+
electron([
87+
{
88+
entry: 'electron/main/index.ts',
89+
},
90+
{
91+
// Preload scripts entry file of the Electron App.
92+
entry: 'electron/preload/index.ts',
93+
onstart(args) {
94+
// Notify the Renderer process to reload the page when the Preload scripts build is complete,
95+
// instead of restarting the entire Electron App.
96+
args.reload()
97+
},
98+
}
99+
]),
100+
],
101+
}
102+
```

guide/plugins.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Plugins
2+
3+
## vite-plugin-electron
4+
5+
6+
## vite-plugin-electron-renderer
7+

guide/templates.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Templates
2+
3+

index.md

+14-17
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,20 @@ hero:
2222
link: https://github.com/electron-vite
2323

2424
features:
25-
- icon:
26-
src: /electron-vite.svg
27-
title: Community support and progress
28-
details: Get support and assistance from a strong open source community
29-
link: /community/acknowledge
30-
31-
- icon:
32-
src: /vite.svg
33-
title: Enjoy the Vite DX
34-
details: Instant server start, lightning fast hot updates, and leverage Vite ecosystem plugins.
35-
link: https://vitejs.dev/
36-
37-
- icon:
38-
src: /electron.svg
39-
title: Electron
40-
details: Build cross-platform desktop apps with JavaScript, HTML, and CSS
41-
link: https://www.electronjs.org/
25+
- icon: 🔥
26+
title: HOT Restart
27+
details: Restart the App immediately after modifying the <font color="var(--vp-c-brand)">Main process</font> code
28+
link: /guide/features.html#hot-restart
29+
30+
- icon: ⚡️
31+
title: HMR
32+
details: The <font color="var(--vp-c-brand)">Renderer process</font> is based on the lightweight and fast HMR provided by Vite
33+
link: /guide/features.html#hmr
34+
35+
- icon: 🔄
36+
title: HOT Reload
37+
details: The Renderer process is automatically refreshed to reload the <font color="var(--vp-c-brand)">Preload scripts</font> after the Preload scripts is modified
38+
link: /guide/features.html#hot-reload
4239

4340
---
4441

plugin/vite-plugin-electron-renderer.md

-158
This file was deleted.

0 commit comments

Comments
 (0)