diff --git a/package.json b/package.json index f751ff6..ba15f97 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "electron-builder": "^23.3.3", "typescript": "^4.7.4", "vite": "^3.0.8", - "vite-plugin-electron": "^0.9.0", + "vite-plugin-electron": "^0.9.1", "vue": "^3.2.37", "vue-tsc": "^0.40.1" }, diff --git a/vite.config.ts b/vite.config.ts index 54539f7..243abee 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 vue from '@vitejs/plugin-vue' -import electron from 'vite-plugin-electron' +import electron, { onstart } from 'vite-plugin-electron' import pkg from './package.json' rmSync('dist', { recursive: true, force: true }) // v14.14.0 @@ -18,11 +14,15 @@ export default defineConfig({ electron({ main: { entry: 'electron/main/index.ts', - vite: withDebug({ + vite: { build: { + // For Debug + sourcemap: true, outDir: 'dist/electron/main', }, - }), + // Will start Electron via VSCode Debug + plugins: [process.env.VSCODE_DEBUG ? onstart() : null], + }, }, preload: { input: { @@ -47,19 +47,3 @@ export default defineConfig({ port: pkg.env.VITE_DEV_SERVER_PORT, }, }) - -function withDebug(config: UserConfig): UserConfig { - if (process.env.VSCODE_DEBUG) { - if (!config.build) config.build = {} - 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 -}