adjusted build system

This commit is contained in:
DJ2LS 2023-10-04 19:54:50 +02:00
parent 80c61eab04
commit 67d7588688
20 changed files with 307 additions and 335 deletions

View file

@ -17,7 +17,7 @@
"plugins": [
"vue"
],
"ignorePatterns": ["**/src/assets/*", "**/src/js/deprecated*"],
"ignorePatterns": ["**/src/assets/*", "**/src/js/deprecated*", "**/node_modules"],
"rules": {
}
}

View file

@ -1 +0,0 @@
"use strict";const o=require("electron"),n=require("node:path");process.env.ELECTRON_DISABLE_SECURITY_WARNINGS="true";process.env.DIST=n.join(__dirname,"../dist");process.env.PUBLIC=o.app.isPackaged?process.env.DIST:n.join(process.env.DIST,"../public");let e;const s=process.env.VITE_DEV_SERVER_URL;function a(){e=new o.BrowserWindow({icon:n.join(process.env.PUBLIC,"electron-vite.svg"),webPreferences:{preload:n.join(__dirname,"preload.js"),backgroundThrottle:!1,nodeIntegration:!0,contextIsolation:!1,enableRemoteModule:!1,sandbox:!1}}),e.webContents.on("did-finish-load",()=>{e==null||e.webContents.send("main-process-message",new Date().toLocaleString())}),s?e.loadURL(s):e.loadFile(n.join(process.env.DIST,"index.html"))}o.app.on("window-all-closed",()=>{e=null});o.app.whenReady().then(a);o.ipcMain.on("request-update-daemon-state",(r,t)=>{e.webContents.send("action-update-daemon-state",t)});

View file

@ -1,45 +0,0 @@
"use strict";function i(e=["complete","interactive"]){return new Promise(t=>{e.includes(document.readyState)?t(!0):document.addEventListener("readystatechange",()=>{e.includes(document.readyState)&&t(!0)})})}const a={append(e,t){Array.from(e.children).find(o=>o===t)||e.appendChild(t)},remove(e,t){Array.from(e.children).find(o=>o===t)&&e.removeChild(t)}};function c(){const e="loaders-css__square-spin",t=`
@keyframes square-spin {
0% {
transform: rotate(0deg);
background-image: url('icon_cube_border.png'); /* Replace with the URL of your image */
background-size: cover; /* Scale the image to cover the entire container */
}
25% { transform: perspective(100px) rotateX(180deg) rotateY(0);
background-image: url('icon_cube_border.png'); /* Replace with the URL of your image */
background-size: cover; /* Scale the image to cover the entire container */
}
50% { transform: perspective(100px) rotateX(180deg) rotateY(180deg);
background-image: url('icon_cube_border.png'); /* Replace with the URL of your image */
background-size: cover; /* Scale the image to cover the entire container */
}
75% { transform: perspective(100px) rotateX(0) rotateY(180deg);
background-image: url('icon_cube_border.png'); /* Replace with the URL of your image */
background-size: cover; /* Scale the image to cover the entire container */
}
100% { transform: perspective(100px) rotateX(0) rotateY(0);
background-image: url('icon_cube_border.png'); /* Replace with the URL of your image */
background-size: cover; /* Scale the image to cover the entire container */
}
}
.${e} > div {
animation-fill-mode: both;
width: 50px;
height: 50px;
background: #fff;
animation: square-spin 3s 0s cubic-bezier(0.09, 0.57, 0.49, 0.9) infinite;
}
.app-loading-wrap {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #282c34;
z-index: 99999;
}
`,o=document.createElement("style"),r=document.createElement("div");return o.id="app-loading-style",o.innerHTML=t,r.className="app-loading-wrap",r.innerHTML=`<div class="${e}"><div></div></div>`,{appendLoading(){a.append(document.head,o),a.append(document.body,r)},removeLoading(){a.remove(document.head,o),a.remove(document.body,r)}}}const{appendLoading:d,removeLoading:n}=c();i().then(d);window.onmessage=e=>{e.data.payload==="removeLoading"&&n()};setTimeout(n,3e3);

View file

@ -5,18 +5,19 @@
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json",
"appId": "YourAppID",
"asar": true,
"productName": "YourAppName",
"directories": {
"output": "release/${version}"
},
"files": [
"dist-electron",
"dist"
"dist",
"dist-electron"
],
"mac": {
"artifactName": "${productName}_${version}.${ext}",
"target": [
"dmg"
]
],
"artifactName": "${productName}-Mac-${version}-Installer.${ext}"
},
"win": {
"target": [
@ -27,12 +28,18 @@
]
}
],
"artifactName": "${productName}_${version}.${ext}"
"artifactName": "${productName}-Windows-${version}-Setup.${ext}"
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
"deleteAppDataOnUninstall": false
},
"linux": {
"target": [
"AppImage"
],
"artifactName": "${productName}-Linux-${version}.${ext}"
}
}

View file

@ -2,21 +2,10 @@
declare namespace NodeJS {
interface ProcessEnv {
/**
* The built directory structure
*
* ```tree
* dist
* index.html
*
* dist-electron
* main.js
* preload.js
*
* ```
*/
VSCODE_DEBUG?: 'true'
DIST_ELECTRON: string
DIST: string
/** /dist/ or /public/ */
PUBLIC: string
VITE_PUBLIC: string
}
}

View file

@ -1,95 +0,0 @@
import { app, BrowserWindow, ipcMain } from 'electron'
import path from 'node:path'
// pinia store setup
import { setActivePinia } from "pinia";
import pinia from "../store/index";
setActivePinia(pinia);
import { useSettingsStore } from "../store/settingsStore.js";
const settings = useSettingsStore(pinia);
//import { useIpcRenderer } from '@vueuse/electron'
//const ipcRenderer = useIpcRenderer()
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
// The built directory structure
//
// ├─┬─┬ dist
// │ │ └── index.html
// │ │
// │ ├─┬ dist-electron
// │ │ ├── main.js
// │ │ └── preload.js
// │
process.env.DIST = path.join(__dirname, '../dist')
process.env.PUBLIC = app.isPackaged ? process.env.DIST : path.join(process.env.DIST, '../public')
let win: BrowserWindow | null
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - Vite@2.x
const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL']
function createWindow() {
win = new BrowserWindow({
icon: path.join(process.env.PUBLIC, 'icon_cube_border.png'),
//webPreferences: {
// preload: path.join(__dirname, 'preload.js'),
//},
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
//preload: path.join(__dirname, 'preload-main.js'),
backgroundThrottle: false,
//preload: require.resolve("preload-main.js"),
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: false,
sandbox: false,
//https://stackoverflow.com/questions/53390798/opening-new-window-electron/53393655
//https://github.com/electron/remote
},
})
win.setMenuBarVisibility(false);
// Test active push message to Renderer-process.
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', (new Date).toLocaleString())
})
win.once("ready-to-show", () => {
console.log(settings.update_channel)
autoUpdater.channel = settings.update_channel;
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.autoDownload = true;
autoUpdater.checkForUpdatesAndNotify();
//autoUpdater.quitAndInstall();
});
if (VITE_DEV_SERVER_URL) {
win.loadURL(VITE_DEV_SERVER_URL)
} else {
// win.loadFile('dist/index.html')
win.loadFile(path.join(process.env.DIST, 'index.html'))
}
}
app.on('window-all-closed', () => {
win = null
})
app.whenReady().then(createWindow)

View file

@ -0,0 +1,117 @@
import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { release } from 'node:os'
import { join } from 'node:path'
// The built directory structure
//
// ├─┬ dist-electron
// │ ├─┬ main
// │ │ └── index.js > Electron-Main
// │ └─┬ preload
// │ └── index.js > Preload-Scripts
// ├─┬ dist
// │ └── index.html > Electron-Renderer
//
process.env.DIST_ELECTRON = join(__dirname, '..')
process.env.DIST = join(process.env.DIST_ELECTRON, '../dist')
process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL
? join(process.env.DIST_ELECTRON, '../public')
: process.env.DIST
// Disable GPU Acceleration for Windows 7
if (release().startsWith('6.1')) app.disableHardwareAcceleration()
// Set application name for Windows 10+ notifications
if (process.platform === 'win32') app.setAppUserModelId(app.getName())
if (!app.requestSingleInstanceLock()) {
app.quit()
process.exit(0)
}
// Remove electron security warnings
// This warning only shows in development mode
// Read more on https://www.electronjs.org/docs/latest/tutorial/security
// process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
let win: BrowserWindow | null = null
// Here, you can also use other preload
const preload = join(__dirname, '../preload/index.js')
const url = process.env.VITE_DEV_SERVER_URL
const indexHtml = join(process.env.DIST, 'index.html')
async function createWindow() {
win = new BrowserWindow({
title: 'Main window',
icon: join(process.env.VITE_PUBLIC, 'favicon.ico'),
webPreferences: {
preload,
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
// Consider using contextBridge.exposeInMainWorld
// Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation
nodeIntegration: true,
contextIsolation: false,
},
})
if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298
win.loadURL(url)
// Open devTool if the app is not packaged
win.webContents.openDevTools()
} else {
win.loadFile(indexHtml)
}
// Test actively push message to the Electron-Renderer
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', new Date().toLocaleString())
})
// Make all links open with the browser, not with the application
win.webContents.setWindowOpenHandler(({ url }) => {
if (url.startsWith('https:')) shell.openExternal(url)
return { action: 'deny' }
})
// win.webContents.on('will-navigate', (event, url) => { }) #344
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
win = null
if (process.platform !== 'darwin') app.quit()
})
app.on('second-instance', () => {
if (win) {
// Focus on the main window if the user tried to open another
if (win.isMinimized()) win.restore()
win.focus()
}
})
app.on('activate', () => {
const allWindows = BrowserWindow.getAllWindows()
if (allWindows.length) {
allWindows[0].focus()
} else {
createWindow()
}
})
// New window example arg: new windows url
ipcMain.handle('open-win', (_, arg) => {
const childWindow = new BrowserWindow({
webPreferences: {
preload,
nodeIntegration: true,
contextIsolation: false,
},
})
if (process.env.VITE_DEV_SERVER_URL) {
childWindow.loadURL(`${url}#${arg}`)
} else {
childWindow.loadFile(indexHtml, { hash: arg })
}
})

View file

@ -1,5 +1,5 @@
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
return new Promise(resolve => {
return new Promise((resolve) => {
if (condition.includes(document.readyState)) {
resolve(true)
} else {
@ -15,12 +15,12 @@ function domReady(condition: DocumentReadyState[] = ['complete', 'interactive'])
const safeDOM = {
append(parent: HTMLElement, child: HTMLElement) {
if (!Array.from(parent.children).find(e => e === child)) {
parent.appendChild(child)
return parent.appendChild(child)
}
},
remove(parent: HTMLElement, child: HTMLElement) {
if (Array.from(parent.children).find(e => e === child)) {
parent.removeChild(child)
return parent.removeChild(child)
}
},
}
@ -35,28 +35,10 @@ function useLoading() {
const className = `loaders-css__square-spin`
const styleContent = `
@keyframes square-spin {
0% {
transform: rotate(0deg);
background-image: url('icon_cube_border.png'); /* Replace with the URL of your image */
background-size: cover; /* Scale the image to cover the entire container */
}
25% { transform: perspective(100px) rotateX(180deg) rotateY(0);
background-image: url('icon_cube_border.png'); /* Replace with the URL of your image */
background-size: cover; /* Scale the image to cover the entire container */
}
50% { transform: perspective(100px) rotateX(180deg) rotateY(180deg);
background-image: url('icon_cube_border.png'); /* Replace with the URL of your image */
background-size: cover; /* Scale the image to cover the entire container */
}
75% { transform: perspective(100px) rotateX(0) rotateY(180deg);
background-image: url('icon_cube_border.png'); /* Replace with the URL of your image */
background-size: cover; /* Scale the image to cover the entire container */
}
100% { transform: perspective(100px) rotateX(0) rotateY(0);
background-image: url('icon_cube_border.png'); /* Replace with the URL of your image */
background-size: cover; /* Scale the image to cover the entire container */
}
25% { transform: perspective(100px) rotateX(180deg) rotateY(0); }
50% { transform: perspective(100px) rotateX(180deg) rotateY(180deg); }
75% { transform: perspective(100px) rotateX(0) rotateY(180deg); }
100% { transform: perspective(100px) rotateX(0) rotateY(0); }
}
.${className} > div {
animation-fill-mode: both;
@ -75,7 +57,7 @@ function useLoading() {
align-items: center;
justify-content: center;
background: #282c34;
z-index: 99999;
z-index: 9;
}
`
const oStyle = document.createElement('style')
@ -103,47 +85,8 @@ function useLoading() {
const { appendLoading, removeLoading } = useLoading()
domReady().then(appendLoading)
window.onmessage = ev => {
window.onmessage = (ev) => {
ev.data.payload === 'removeLoading' && removeLoading()
}
setTimeout(removeLoading, 3000)
import { autoUpdater } from 'electron-updater';
autoUpdater.channel = settings.update_channel;
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.autoDownload = true;
autoUpdater.checkForUpdatesAndNotify();
// LISTENER FOR UPDATER EVENTS
autoUpdater.on("update-available", (info) => {
console.log("update available");
});
autoUpdater.on("update-not-available", (info) => {
console.log("update not available");
});
autoUpdater.on("update-downloaded", (info) => {
console.log("update downloaded");
// we need to call this at this point.
// if an update is available and we are force closing the app
// the entire screen crashes...
//console.log('quit application and install update');
//autoUpdater.quitAndInstall();
});
autoUpdater.on("checking-for-update", () => {
console.log("checking for update");
});
autoUpdater.on("download-progress", (progress) => {
});
autoUpdater.on("error", (error) => {
console.log("update error");
});
setTimeout(removeLoading, 4999)

View file

@ -4,6 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<title>FreeDATA</title>
</head>
<body>

View file

@ -2,11 +2,11 @@
"name": "FreeDATA",
"private": true,
"version": "0.11.0-alpha",
"main": "dist-electron/main.js",
"main": "dist-electron/main/index.js",
"scripts": {
"start": "vite",
"dev": "vite",
"build": "vue-tsc && vite build && electron-builder",
"dev": "vite",
"build": "vue-tsc --noEmit && vite build && electron-builder",
"preview": "vite preview",
"lint": "eslint --ext .js,.vue src",
"lint-fix": "eslint --ext .js,.vue --fix src"
@ -37,6 +37,7 @@
"browser-image-compression": "^2.0.2",
"chart.js": "^4.3.3",
"chartjs-plugin-annotation": "^3.0.1",
"electron-builder-notarize": "^1.5.1",
"electron-log": "^4.4.8",
"electron-updater": "^6.1.1",
"emoji-picker-element": "^1.18.3",
@ -52,14 +53,13 @@
"socket.io": "^4.7.2",
"uuid": "^9.0.0",
"vue": "^3.3.4",
"vue-chartjs": "^5.2.0",
"winston": "^3.10.0"
"vue-chartjs": "^5.2.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@vitejs/plugin-vue": "^4.1.0",
"electron": "^24.8.2",
"electron-builder": "^23.6.0",
"@vitejs/plugin-vue": "^4.4.0",
"electron": "^26.0.0",
"electron-builder": "^24.6.3",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard-with-typescript": "^39.1.0",
@ -70,8 +70,9 @@
"eslint-plugin-vue": "^9.17.0",
"typescript": "^5.2.2",
"vite": "^4.3.2",
"vite-plugin-electron": "^0.11.2",
"vite-plugin-electron": "^0.14.0",
"vite-plugin-electron-renderer": "^0.14.5",
"vue": "^3.3.4",
"vue-tsc": "^1.4.2"
},
"build": {
@ -119,6 +120,19 @@
"!**/.git"
]
}
],
"files": [
"**/*",
"!**/*.ts",
"!*.map",
"!package.json",
"!package-lock.json",
{
"from": "../dist",
"filter": [
"**/*"
]
}
]
}
}

View file

@ -1,5 +1,4 @@
<script setup lang="ts">
import { saveSettingsToFile } from "../js/settingsHandler";
import { setActivePinia } from "pinia";
import pinia from "../store/index";
@ -8,8 +7,6 @@ setActivePinia(pinia);
import { useStateStore } from "../store/stateStore.js";
const state = useStateStore(pinia);
import { useSettingsStore } from "../store/settingsStore.js";
const settings = useSettingsStore(pinia);
</script>
<template>
@ -156,11 +153,11 @@ const settings = useSettingsStore(pinia);
class="bi"
style="font-size: 1rem"
v-bind:class="{
'bi-reception-0': state.speed_level === '0',
'bi-reception-1': state.speed_level === '1',
'bi-reception-2': state.speed_level === '2',
'bi-reception-3': state.speed_level === '3',
'bi-reception-4': state.speed_level === '4',
'bi-reception-0': state.speed_level === 0,
'bi-reception-1': state.speed_level === 1,
'bi-reception-2': state.speed_level === 2,
'bi-reception-3': state.speed_level === 3,
'bi-reception-4': state.speed_level === 4,
}"
></i>
</button>

View file

@ -1,13 +1,9 @@
<script setup lang="ts">
import { saveSettingsToFile } from "../js/settingsHandler";
import { setActivePinia } from "pinia";
import pinia from "../store/index";
setActivePinia(pinia);
import { useSettingsStore } from "../store/settingsStore.js";
const settings = useSettingsStore(pinia);
import { useStateStore } from "../store/stateStore.js";
const state = useStateStore(pinia);
@ -17,7 +13,7 @@ function tuneAudio() {
sendTestFrame();
}
function set_audio_level(obj) {
function set_audio_level() {
setTxAudioLevel(state.audio_level);
}
</script>
@ -624,7 +620,7 @@ function set_audio_level(obj) {
<div class="card mb-3">
<div class="card-body">
<h5 class="card-title">
<button type="button" class="btn btn-sm btn-outline-secondary">
<button type="button" class="btn btn-sm btn-outline-secondary" @click="tuneAudio">
Tune
</button>
</h5>

View file

@ -8,7 +8,7 @@ setActivePinia(pinia);
import { useSettingsStore } from "../store/settingsStore.js";
const settings = useSettingsStore(pinia);
function selectRadioControl(obj) {
function selectRadioControl() {
switch (event.target.id) {
case "list-rig-control-none-list":
settings.radiocontrol = "disabled";
@ -25,6 +25,14 @@ function selectRadioControl(obj) {
}
saveSettingsToFile();
}
function testHamlib(){
console.log("not yet implemented")
alert("not yet implemented")
}
</script>
<template>

View file

@ -1,5 +1,4 @@
<script setup lang="ts">
import { saveSettingsToFile } from "../js/settingsHandler";
import { setActivePinia } from "pinia";
import pinia from "../store/index";

View file

@ -37,7 +37,7 @@ const dateFormatHours = new Intl.DateTimeFormat(navigator.language, {
hour12: false,
});
// split character
const split_char = "\0;\1;";
//const split_char = "\0;\1;";
// global for our selected file we want to transmit
// ----------------- some chat globals
var filetype = "";

View file

@ -1,7 +1,11 @@
import { defineStore } from "pinia";
import { ref, computed } from "vue";
import { ref } from "vue";
export const useSettingsStore = defineStore("settingsStore", () => {
// audio
var tx_audio = ref()
var rx_audio = ref()
// network
var tnc_host = ref("127.0.0.1");
var tnc_port = ref(3000);
@ -44,8 +48,6 @@ export const useSettingsStore = defineStore("settingsStore", () => {
var hamlib_ptt_port = ref("ignore");
var hamlib_dcd = ref("ignore");
var hamlbib_serialspeed_ptt = ref(9600);
var hamlib_rigctld_port = ref(4532);
var hamlib_rigctld_ip = ref("127.0.0.1");
var hamlib_rigctld_path = ref("");
var hamlib_rigctld_server_port = ref(4532);
var hamlib_rigctld_custom_args = ref("");
@ -132,6 +134,8 @@ export const useSettingsStore = defineStore("settingsStore", () => {
auto_start: auto_start.value,
enable_sys_notification: enable_sys_notification.value,
enable_mesh_features: enable_mesh_features.value,
tx_audio: tx_audio.value,
rx_audio: rx_audio.value,
};
return config_export;
@ -171,8 +175,6 @@ export const useSettingsStore = defineStore("settingsStore", () => {
hamlib_ptt_port,
hamlib_dcd,
hamlbib_serialspeed_ptt,
hamlib_rigctld_port,
hamlib_rigctld_ip,
hamlib_rigctld_path,
hamlib_rigctld_server_port,
hamlib_rigctld_custom_args,
@ -197,5 +199,7 @@ export const useSettingsStore = defineStore("settingsStore", () => {
tx_delay,
enable_mesh_features,
getJSON,
tx_audio,
rx_audio
};
});

View file

@ -1 +1,8 @@
/// <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}

View file

@ -1,29 +1,37 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"allowJs": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"moduleResolution": "Node",
"strict": true,
"jsx": "preserve",
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"skipLibCheck": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
"allowJs": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "electron"],
"references": [{ "path": "./tsconfig.node.json" }]
"include": ["src"],
"references": [
{ "path": "./tsconfig.node.json" }
]
}

View file

@ -1,10 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"moduleResolution": "Node",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
"include": ["vite.config.ts", "package.json", "electron"]
}

View file

@ -1,62 +1,85 @@
import { rmSync } from 'node:fs'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron'
import renderer from 'vite-plugin-electron-renderer'
import vue from '@vitejs/plugin-vue'
import { notBundle } from 'vite-plugin-electron/plugin'
import pkg from './package.json'
// https://vitejs.dev/config/
export default defineConfig({
server: {
open: true,
port: 5173,
},
build: {
minify: false
},
plugins: [
vue(),
electron([
export default defineConfig(({ command }) => {
rmSync('dist-electron', { recursive: true, force: true })
{
// Main-Process entry file of the Electron App.
entry: 'electron/main.ts',
},
/*
{
// Daemon-Process entry file of the Electron App.
entry: 'electron/sock.js',
},
{
// Daemon-Process entry file of the Electron App.
entry: 'electron/daemon.js',
},
{
// Daemon-Process entry file of the Electron App.
entry: 'electron/freedata.js',
},
{
entry: 'electron/preload-main.js',
onstart(options) {
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
// instead of restarting the entire Electron App.
options.reload()
const isServe = command === 'serve'
const isBuild = command === 'build'
const sourcemap = isServe || !!process.env.VSCODE_DEBUG
return {
plugins: [
vue(),
electron([
{
// Main process entry file of the Electron App.
entry: 'electron/main/index.ts',
onstart({ startup }) {
if (process.env.VSCODE_DEBUG) {
console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')
} else {
startup()
}
},
vite: {
build: {
sourcemap,
minify: isBuild,
outDir: 'dist-electron/main',
rollupOptions: {
// Some third-party Node.js libraries may not be built correctly by Vite, especially `C/C++` addons,
// we can use `external` to exclude them to ensure they work correctly.
// Others need to put them in `dependencies` to ensure they are collected into `app.asar` after the app is built.
// Of course, this is not absolute, just this way is relatively simple. :)
external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}),
},
},
plugins: [
// This is just an option to improve build performance, it's non-deterministic!
// e.g. `import log from 'electron-log'` -> `const log = require('electron-log')`
isServe && notBundle(),
],
},
},
},
*/
{
entry: 'electron/preload.ts',
onstart(options) {
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
// instead of restarting the entire Electron App.
options.reload()
},
},
{
entry: 'electron/preload/index.ts',
onstart({ reload }) {
// Notify the Renderer process to reload the page when the Preload scripts build is complete,
// instead of restarting the entire Electron App.
reload()
},
vite: {
build: {
sourcemap: sourcemap ? 'inline' : undefined, // #332
minify: isBuild,
outDir: 'dist-electron/preload',
rollupOptions: {
external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}),
},
},
plugins: [
isServe && notBundle(),
],
},
}
]),
// Use Node.js API in the Renderer process
renderer(),
],
),
renderer(),
],
server: process.env.VSCODE_DEBUG && (() => {
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
return {
host: url.hostname,
port: +url.port,
}
})(),
clearScreen: false,
}
})