chore(docs): update

This commit is contained in:
草鞋没号 2021-12-20 09:48:32 +08:00
parent 6a248a873a
commit 31dc1888a2
2 changed files with 10 additions and 4 deletions

View File

@ -67,14 +67,17 @@
## Use Electron, NodeJs API
> 🚨 By default, Electron don't support the use of API related to Electron and NoeJs in the Renderer-process, but someone still need to use it. If so, you can see the 👉 npm-package **[vitejs-plugin-electron](https://www.npmjs.com/package/vitejs-plugin-electron)** or another template **[vite-webpack-electron](https://github.com/caoxiemeihao/vite-webpack-electron)**
> 🚧 By default, Electron don't support the use of API related to Electron and NoeJs in the Renderer-process, but someone still need to use it. If so, you can see the 👉 npm-package **[vitejs-plugin-electron](https://www.npmjs.com/package/vitejs-plugin-electron)** or another template **[vite-webpack-electron](https://github.com/caoxiemeihao/vite-webpack-electron)**
#### All Electron, NodeJs API invoke passed `Preload-script`
* **src/preload/index.ts**
```typescript
// --------- Expose some API to Renderer process. ---------
import fs from 'fs'
import { contextBridge, ipcRenderer } from 'electron'
// --------- Expose some API to Renderer-process. ---------
contextBridge.exposeInMainWorld('fs', fs)
contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer)
```

View File

@ -68,7 +68,7 @@
## 渲染进程使用 NodeJs API
> 🚨 因为安全的原因 Electron 默认不支持在 渲染进程 中使用 NodeJs API但是有些小沙雕就是想这么干拦都拦不住实在想那么干的话这里有个 👉 npm 包 **[vitejs-plugin-electron](https://www.npmjs.com/package/vitejs-plugin-electron)** 或者使用另一个模板 **[vite-webpack-electron](https://github.com/caoxiemeihao/vite-webpack-electron)**
> 🚧 因为安全的原因 Electron 默认不支持在 渲染进程 中使用 NodeJs API但是有些小沙雕就是想这么干拦都拦不住实在想那么干的话这里有个 👉 npm 包 **[vitejs-plugin-electron](https://www.npmjs.com/package/vitejs-plugin-electron)** 或者使用另一个模板 **[vite-webpack-electron](https://github.com/caoxiemeihao/vite-webpack-electron)**
- 推荐所有的 NodeJs、Electron API 通过 `preload-script` 注入到 渲染进程中,例如:
@ -76,7 +76,10 @@
* **src/preload/index.ts**
```typescript
// --------- Expose some API to Renderer process. ---------
import fs from 'fs'
import { contextBridge, ipcRenderer } from 'electron'
// --------- Expose some API to Renderer-process. ---------
contextBridge.exposeInMainWorld('fs', fs)
contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer)
```