Merge pull request #93 from xhayper/patch-1

feat: improvement to template
This commit is contained in:
草鞋没号 2022-12-27 11:28:20 +08:00 committed by GitHub
commit 9f414cef12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 11 deletions

1
.npmrc Normal file
View File

@ -0,0 +1 @@
shamefully-hoist=true

View File

@ -12,7 +12,7 @@ import { join } from 'node:path'
// ├─┬ dist // ├─┬ dist
// │ └── index.html > Electron-Renderer // │ └── index.html > Electron-Renderer
// //
process.env.DIST_ELECTRON = join(__dirname, '..') process.env.DIST_ELECTRON = join(__dirname, '../')
process.env.DIST = join(process.env.DIST_ELECTRON, '../dist') process.env.DIST = join(process.env.DIST_ELECTRON, '../dist')
process.env.PUBLIC = process.env.VITE_DEV_SERVER_URL process.env.PUBLIC = process.env.VITE_DEV_SERVER_URL
? join(process.env.DIST_ELECTRON, '../public') ? join(process.env.DIST_ELECTRON, '../public')
@ -38,7 +38,7 @@ let win: BrowserWindow | null = null
// Here, you can also use other preload // Here, you can also use other preload
const preload = join(__dirname, '../preload/index.js') const preload = join(__dirname, '../preload/index.js')
const url = process.env.VITE_DEV_SERVER_URL const url = process.env.VITE_DEV_SERVER_URL
const indexHtml = join('dist/', 'index.html') const indexHtml = join(process.env.DIST, 'index.html')
async function createWindow() { async function createWindow() {
win = new BrowserWindow({ win = new BrowserWindow({
@ -54,11 +54,10 @@ async function createWindow() {
}, },
}) })
// Open devTool if the app is not packaged
win.webContents.openDevTools()
if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298 if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298
win.loadURL(url) win.loadURL(url)
// Open devTool if the app is not packaged
win.webContents.openDevTools()
} else { } else {
win.loadFile(indexHtml) win.loadFile(indexHtml)
} }
@ -114,4 +113,4 @@ ipcMain.handle('open-win', (_, arg) => {
} else { } else {
childWindow.loadFile(indexHtml, { hash: arg }) childWindow.loadFile(indexHtml, { hash: arg })
} }
}) })

View File

@ -1,7 +1,7 @@
{ {
"name": "electron-vite-react", "name": "electron-vite-react",
"version": "2.1.0", "version": "2.1.0",
"main": "dist-electron/electron/main/index.js", "main": "dist-electron/main/index.js",
"description": "Electron Vite React boilerplate.", "description": "Electron Vite React boilerplate.",
"author": "草鞋没号 <308487730@qq.com>", "author": "草鞋没号 <308487730@qq.com>",
"license": "MIT", "license": "MIT",
@ -18,7 +18,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^18.0.26", "@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9", "@types/react-dom": "^18.0.10",
"@vitejs/plugin-react": "^3.0.0", "@vitejs/plugin-react": "^3.0.0",
"electron": "^22.0.0", "electron": "^22.0.0",
"electron-builder": "^23.6.0", "electron-builder": "^23.6.0",
@ -27,7 +27,7 @@
"sass": "^1.57.1", "sass": "^1.57.1",
"typescript": "^4.9.4", "typescript": "^4.9.4",
"vite": "^4.0.3", "vite": "^4.0.3",
"vite-electron-plugin": "^0.6.0", "vite-electron-plugin": "^0.6.3",
"vite-plugin-electron-renderer": "^0.11.3" "vite-plugin-electron-renderer": "^0.11.3"
}, },
"engines": { "engines": {

View File

@ -23,8 +23,7 @@ export default defineConfig({
react(), react(),
electron({ electron({
include: [ include: [
'electron', 'electron'
'preload',
], ],
transformOptions: { transformOptions: {
sourcemap: isDevelopment sourcemap: isDevelopment