mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-02-26 13:00:09 +08:00
refactor: better Debug config
This commit is contained in:
parent
f53dba80a3
commit
642403f478
@ -1,12 +1,8 @@
|
|||||||
import { rmSync } from 'fs'
|
import { rmSync } from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import {
|
import { defineConfig } from 'vite'
|
||||||
type Plugin,
|
|
||||||
type UserConfig,
|
|
||||||
defineConfig,
|
|
||||||
} from 'vite'
|
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import electron from 'vite-plugin-electron'
|
import electron, { onstart } from 'vite-plugin-electron'
|
||||||
import pkg from './package.json'
|
import pkg from './package.json'
|
||||||
|
|
||||||
rmSync('dist', { recursive: true, force: true }) // v14.14.0
|
rmSync('dist', { recursive: true, force: true }) // v14.14.0
|
||||||
@ -18,11 +14,15 @@ export default defineConfig({
|
|||||||
electron({
|
electron({
|
||||||
main: {
|
main: {
|
||||||
entry: 'electron/main/index.ts',
|
entry: 'electron/main/index.ts',
|
||||||
vite: withDebug({
|
vite: {
|
||||||
build: {
|
build: {
|
||||||
|
// For Debug
|
||||||
|
sourcemap: true,
|
||||||
outDir: 'dist/electron/main',
|
outDir: 'dist/electron/main',
|
||||||
},
|
},
|
||||||
}),
|
// Will start Electron via VSCode Debug
|
||||||
|
plugins: [process.env.VSCODE_DEBUG ? onstart() : null],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
preload: {
|
preload: {
|
||||||
input: {
|
input: {
|
||||||
@ -47,19 +47,3 @@ export default defineConfig({
|
|||||||
port: pkg.env.VITE_DEV_SERVER_PORT,
|
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
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user