2022-07-24 07:26:24 +08:00
|
|
|
import { rmSync } from 'fs'
|
2022-08-24 21:00:38 +08:00
|
|
|
import { defineConfig } from 'vite'
|
2022-06-13 22:10:18 +08:00
|
|
|
import vue from '@vitejs/plugin-vue'
|
2022-10-03 09:16:14 +08:00
|
|
|
import electron from 'vite-electron-plugin'
|
|
|
|
import { customStart } from 'vite-electron-plugin/plugin'
|
2022-10-18 16:06:39 +08:00
|
|
|
import renderer from 'vite-plugin-electron-renderer'
|
2022-06-30 22:16:12 +08:00
|
|
|
import pkg from './package.json'
|
2022-06-13 22:10:18 +08:00
|
|
|
|
2022-10-03 09:16:14 +08:00
|
|
|
rmSync('dist-electron', { recursive: true, force: true })
|
2022-06-15 21:47:33 +08:00
|
|
|
|
2022-06-13 22:10:18 +08:00
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig({
|
2022-06-14 20:53:01 +08:00
|
|
|
plugins: [
|
|
|
|
vue(),
|
2022-06-27 10:26:32 +08:00
|
|
|
electron({
|
2022-10-03 09:16:14 +08:00
|
|
|
include: ['electron'],
|
|
|
|
transformOptions: {
|
|
|
|
sourcemap: !!process.env.VSCODE_DEBUG,
|
2022-06-27 10:26:32 +08:00
|
|
|
},
|
2022-10-03 09:16:14 +08:00
|
|
|
// Will start Electron via VSCode Debug
|
|
|
|
plugins: process.env.VSCODE_DEBUG
|
|
|
|
? [customStart(debounce(() => console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')))]
|
|
|
|
: undefined,
|
2022-06-27 10:26:32 +08:00
|
|
|
}),
|
2022-10-18 16:06:39 +08:00
|
|
|
// Use Node.js API in the Renderer-process
|
|
|
|
renderer({
|
|
|
|
nodeIntegration: true,
|
|
|
|
}),
|
2022-06-14 20:53:01 +08:00
|
|
|
],
|
2022-10-03 09:16:14 +08:00
|
|
|
server: process.env.VSCODE_DEBUG ? (() => {
|
|
|
|
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
|
|
|
|
return {
|
|
|
|
host: url.hostname,
|
|
|
|
port: +url.port,
|
|
|
|
}
|
|
|
|
})() : undefined,
|
|
|
|
clearScreen: false,
|
2022-10-28 10:00:23 +08:00
|
|
|
build: {
|
|
|
|
assetsDir: '', // #287
|
|
|
|
},
|
2022-06-13 22:10:18 +08:00
|
|
|
})
|
2022-10-03 09:16:14 +08:00
|
|
|
|
|
|
|
function debounce<Fn extends (...args: any[]) => void>(fn: Fn, delay = 299) {
|
|
|
|
let t: NodeJS.Timeout
|
|
|
|
return ((...args) => {
|
|
|
|
clearTimeout(t)
|
|
|
|
t = setTimeout(() => fn(...args), delay)
|
|
|
|
}) as Fn
|
|
|
|
}
|