feat: support preload script hot reload

This commit is contained in:
草鞋没号
2021-10-25 20:45:37 +08:00
parent d05338ca1b
commit a4ca740c99
7 changed files with 130 additions and 40 deletions

View File

@@ -1,5 +1,21 @@
import './communication'
import { domReady } from './utils/dom'
import { loading } from './loading'
import fs from 'fs'
import { contextBridge, ipcRenderer } from 'electron'
import { domReady, injectWsCode } from './utils'
import { useLoading } from './loading'
domReady().then(loading)
const isDev = process.env.NODE_ENV === 'development'
const { removeLoading, appendLoading } = useLoading()
domReady().then(() => {
appendLoading()
isDev && injectWsCode({
host: '127.0.0.1',
port: process.env.PORT_WS as string, // process.env.npm_package_env_PORT_WS
})
})
// --------- Expose some API to Renderer process. ---------
contextBridge.exposeInMainWorld('fs', fs)
contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer)
contextBridge.exposeInMainWorld('removeLoading', removeLoading)