mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-01-19 03:46:35 +08:00
Merge pull request #203 from electron-vite/refactor/220724-debug
refactor: better Debug logic
This commit is contained in:
commit
8b740153f2
13
.vscode/.debug.script.mjs
vendored
13
.vscode/.debug.script.mjs
vendored
@ -11,8 +11,13 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
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(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', 'dev'], { stdio: 'inherit' })
|
||||
spawn(
|
||||
// TODO: terminate `npm run dev` when Debug exits.
|
||||
process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
||||
['run', 'dev'],
|
||||
{
|
||||
stdio: 'inherit',
|
||||
env: Object.assign(process.env, { VSCODE_DEBUG: 'true' }),
|
||||
},
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { existsSync, rmSync } from 'fs'
|
||||
import { rmSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { defineConfig, Plugin, UserConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
@ -44,20 +44,16 @@ export default defineConfig({
|
||||
})
|
||||
|
||||
function withDebug(config: UserConfig): UserConfig {
|
||||
const DebugFile = join(__dirname, 'node_modules/.electron-vite-debug')
|
||||
const isDebug = existsSync(DebugFile)
|
||||
|
||||
if (isDebug) {
|
||||
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)
|
||||
rmSync(DebugFile)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user