refactor: better Debug

This commit is contained in:
草鞋没号 2022-08-25 08:29:44 +08:00
parent 5b21e8f189
commit ebb226e917
4 changed files with 12 additions and 10 deletions

View File

@ -8,7 +8,7 @@ const pkg = createRequire(import.meta.url)('../package.json')
const __dirname = path.dirname(fileURLToPath(import.meta.url))
// write .debug.env
const envContent = Object.entries(pkg.env).map(([key, val]) => `${key}=${val}`)
const envContent = Object.entries(pkg.debug.env).map(([key, val]) => `${key}=${val}`)
fs.writeFileSync(path.join(__dirname, '.debug.env'), envContent.join('\n'))
// bootstrap

View File

@ -28,8 +28,7 @@ export const ROOT_PATH = {
let win: BrowserWindow | null = null
// Here, you can also use other preload
const preload = join(__dirname, '../preload/index.js')
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin
const url = `http://${process.env['VITE_DEV_SERVER_HOST']}:${process.env['VITE_DEV_SERVER_PORT']}`
const url = process.env.VITE_DEV_SERVER_URL
const indexHtml = join(ROOT_PATH.dist, 'index.html')
async function createWindow() {

View File

@ -23,9 +23,12 @@
"vue": "^3.2.37",
"vue-tsc": "^0.40.1"
},
"env": {
"VITE_DEV_SERVER_HOST": "127.0.0.1",
"VITE_DEV_SERVER_PORT": 3344
"debug": {
"env": {
"VITE_DEV_SERVER_HOST": "127.0.0.1",
"VITE_DEV_SERVER_PORT": 3344,
"VITE_DEV_SERVER_URL": "http://127.0.0.1:3344"
}
},
"keywords": [
"electron",

View File

@ -42,8 +42,8 @@ export default defineConfig({
renderer: {},
}),
],
server: {
host: pkg.env.VITE_DEV_SERVER_HOST,
port: pkg.env.VITE_DEV_SERVER_PORT,
},
server: process.env.VSCODE_DEBUG ? {
host: pkg.debug.env.VITE_DEV_SERVER_HOST,
port: pkg.debug.env.VITE_DEV_SERVER_PORT,
} : undefined,
})