From ad1096433e75c1c24b885c7275aafd742841ef70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Fri, 22 Jul 2022 15:26:37 +0800 Subject: [PATCH 1/4] chore: use reference `electron-env.d.ts` type --- electron/electron-env.d.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.ts index 7d79242..6acc9e1 100644 --- a/electron/electron-env.d.ts +++ b/electron/electron-env.d.ts @@ -1,7 +1 @@ -declare namespace NodeJS { - interface ProcessEnv { - NODE_ENV: 'development' | 'production' - readonly VITE_DEV_SERVER_HOST: string - readonly VITE_DEV_SERVER_PORT: string - } -} +/// \ No newline at end of file From 1c3614081dd6dee11dd0eb297f08f49ed542b300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Fri, 22 Jul 2022 15:27:51 +0800 Subject: [PATCH 2/4] chore: bump vite-plugin-electron to 0.8.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 723013e..f0c1fa7 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "sass": "^1.53.0", "typescript": "^4.7.4", "vite": "^2.9.14", - "vite-plugin-electron": "^0.8.0" + "vite-plugin-electron": "^0.8.1" }, "env": { "VITE_DEV_SERVER_HOST": "127.0.0.1", From fe103943f2baa2951d4d9d7860ab6044bac78ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Fri, 22 Jul 2022 15:28:23 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat(=F0=9F=8C=B1):=20support=20Debug=20in?= =?UTF-8?q?=20VSCode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/.debug.script.mjs | 4 ++++ vite.config.ts | 29 ++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.vscode/.debug.script.mjs b/.vscode/.debug.script.mjs index 8091ced..cbc3357 100644 --- a/.vscode/.debug.script.mjs +++ b/.vscode/.debug.script.mjs @@ -12,8 +12,12 @@ const pkg = require('../package.json') const envContent = Object.entries(pkg.env).map(([key, val]) => `${key}=${val}`) fs.writeFileSync(path.join(__dirname, '.debug.env'), envContent.join('\n')) +// for debug +fs.writeFileSync(path.join(__dirname, '../node_modules/.electron-vite-debug'), '') + // bootstrap spawn( + // TODO: terminate `npm run dev` when Debug exits. process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', 'dev'], { stdio: 'inherit' }, diff --git a/vite.config.ts b/vite.config.ts index 3c8855d..a89efae 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,6 @@ -import { rmSync } from 'fs' +import { existsSync, rmSync } from 'fs' import { join } from 'path' -import { defineConfig } from 'vite' +import { defineConfig, UserConfig, Plugin } from 'vite' import react from '@vitejs/plugin-react' import electron from 'vite-plugin-electron' import pkg from './package.json' @@ -20,12 +20,11 @@ export default defineConfig({ electron({ main: { entry: 'electron/main/index.ts', - vite: { + vite: withDebug({ build: { - sourcemap: false, outDir: 'dist/electron/main', }, - }, + }), }, preload: { input: { @@ -49,3 +48,23 @@ export default defineConfig({ port: pkg.env.VITE_DEV_SERVER_PORT, }, }) + +function withDebug(config: UserConfig): UserConfig { + const debugFile = join(__dirname, 'node_modules/.electron-vite-debug') + const isDebug = existsSync(debugFile) + + if (isDebug) { + config.build.sourcemap = true + config.plugins = (config.plugins || []).concat({ + name: 'electron-vite-debug', + configResolved(config) { + // TODO: when the next version of `vite-plugine-electron` is released, use the config hook. + const index = config.plugins.findIndex(p => p.name === 'electron-main-watcher'); + (config.plugins as Plugin[]).splice(index, 1) + rmSync(debugFile) + }, + }) + } + + return config +} From 0ab99a990cc1046938044a344a62fcdcd290f08f Mon Sep 17 00:00:00 2001 From: Paul <40315177+PAXANDDOS@users.noreply.github.com> Date: Fri, 22 Jul 2022 12:11:16 +0300 Subject: [PATCH 4/4] chore: update & remove --- package.json | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index f0c1fa7..48e2ed6 100644 --- a/package.json +++ b/package.json @@ -14,20 +14,18 @@ "engines": { "node": ">=14.17.0" }, - "dependencies": { - "electron-store": "^8.0.2" - }, + "dependencies": {}, "devDependencies": { "@types/react": "^18.0.15", "@types/react-dom": "^18.0.6", - "@vitejs/plugin-react": "^1.3.2", - "electron": "^19.0.8", + "@vitejs/plugin-react": "^2.0.0", + "electron": "^19.0.9", "electron-builder": "^23.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", "sass": "^1.53.0", "typescript": "^4.7.4", - "vite": "^2.9.14", + "vite": "^3.0.2", "vite-plugin-electron": "^0.8.1" }, "env": {