From 05cdb82d15e8ece9080d9c3cd4f929f302d2298c 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: Wed, 24 Aug 2022 19:34:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20better=20Debug=20config=20?= =?UTF-8?q?=F0=9F=90=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vite.config.ts | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index f7d9fa5..4d81e95 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,12 +1,8 @@ import { rmSync } from 'fs' import path from 'path' -import { - type Plugin, - type UserConfig, - defineConfig, -} from 'vite' +import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' -import electron from 'vite-plugin-electron' +import electron, { onstart } from 'vite-plugin-electron' import pkg from './package.json' rmSync(path.join(__dirname, 'dist'), { recursive: true, force: true }) // v14.14.0 @@ -24,11 +20,14 @@ export default defineConfig({ electron({ main: { entry: 'electron/main/index.ts', - vite: withDebug({ + vite: { build: { + // For debug + sourcemap: true, outDir: 'dist/electron/main', }, - }), + plugins: [process.env.VSCODE_DEBUG ? onstart() : null], + }, }, preload: { input: { @@ -56,18 +55,3 @@ export default defineConfig({ minify: false } }) - -function withDebug(config: UserConfig): UserConfig { - if (process.env.VSCODE_DEBUG) { - config.build.sourcemap = true - config.plugins = (config.plugins || []).concat({ - name: 'electron-vite-debug', - configResolved(config) { - const index = config.plugins.findIndex(p => p.name === 'electron-main-watcher'); - // At present, Vite can only modify plugins in configResolved hook. - (config.plugins as Plugin[]).splice(index, 1) - }, - }) - } - return config -}