Merge pull request #51 from electron-vite/chore/220723

Chore/220723
This commit is contained in:
草鞋没号 2022-07-23 17:20:10 +08:00 committed by GitHub
commit 4bcb4e99bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 12 deletions

View File

@ -12,13 +12,13 @@ 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' },
{
stdio: 'inherit',
env: Object.assign(process.env, { VSCODE_DEBUG: 'true' }),
},
)

View File

@ -1,4 +1,4 @@
import { existsSync, rmSync } from 'fs'
import { rmSync } from 'fs'
import { join } from 'path'
import { defineConfig, UserConfig, Plugin } from 'vite'
import react from '@vitejs/plugin-react'
@ -50,21 +50,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) {
// 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');
// At present, Vite can only modify plugins in configResolved hook.
(config.plugins as Plugin[]).splice(index, 1)
rmSync(debugFile)
},
})
}
return config
}