src: update build and dev
This commit is contained in:
1
concord-client/.gitignore
vendored
1
concord-client/.gitignore
vendored
@@ -11,6 +11,7 @@ node_modules
|
|||||||
dist
|
dist
|
||||||
dist-ssr
|
dist-ssr
|
||||||
*.local
|
*.local
|
||||||
|
release/
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
|||||||
@@ -1,45 +1,30 @@
|
|||||||
import { app, BrowserWindow } from "electron";
|
import { app as n, BrowserWindow as i } from "electron";
|
||||||
import { createRequire } from "node:module";
|
import { fileURLToPath as c } from "node:url";
|
||||||
import { fileURLToPath } from "node:url";
|
import o from "node:path";
|
||||||
import path from "node:path";
|
const t = o.dirname(c(import.meta.url));
|
||||||
createRequire(import.meta.url);
|
process.env.APP_ROOT = o.join(t, "..");
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const s = process.env.VITE_DEV_SERVER_URL, R = o.join(process.env.APP_ROOT, "dist-electron"), r = o.join(process.env.APP_ROOT, "dist");
|
||||||
process.env.APP_ROOT = path.join(__dirname, "..");
|
process.env.VITE_PUBLIC = s ? o.join(process.env.APP_ROOT, "public") : r;
|
||||||
const VITE_DEV_SERVER_URL = process.env["VITE_DEV_SERVER_URL"];
|
let e;
|
||||||
const MAIN_DIST = path.join(process.env.APP_ROOT, "dist-electron");
|
function l() {
|
||||||
const RENDERER_DIST = path.join(process.env.APP_ROOT, "dist");
|
e = new i({
|
||||||
process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL ? path.join(process.env.APP_ROOT, "public") : RENDERER_DIST;
|
icon: o.join(process.env.VITE_PUBLIC, "electron-vite.svg"),
|
||||||
let win;
|
|
||||||
function createWindow() {
|
|
||||||
win = new BrowserWindow({
|
|
||||||
icon: path.join(process.env.VITE_PUBLIC, "electron-vite.svg"),
|
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, "preload.mjs")
|
preload: o.join(t, "preload.mjs")
|
||||||
}
|
|
||||||
});
|
|
||||||
win.webContents.on("did-finish-load", () => {
|
|
||||||
win == null ? void 0 : win.webContents.send("main-process-message", (/* @__PURE__ */ new Date()).toLocaleString());
|
|
||||||
});
|
|
||||||
if (VITE_DEV_SERVER_URL) {
|
|
||||||
win.loadURL(VITE_DEV_SERVER_URL);
|
|
||||||
} else {
|
|
||||||
win.loadFile(path.join(RENDERER_DIST, "index.html"));
|
|
||||||
}
|
}
|
||||||
|
}), e.webContents.on("did-finish-load", () => {
|
||||||
|
e == null || e.webContents.send("main-process-message", (/* @__PURE__ */ new Date()).toLocaleString());
|
||||||
|
}), s ? e.loadURL(s) : e.loadFile(o.join(r, "index.html"));
|
||||||
}
|
}
|
||||||
app.on("window-all-closed", () => {
|
n.on("window-all-closed", () => {
|
||||||
if (process.platform !== "darwin") {
|
process.platform !== "darwin" && (n.quit(), e = null);
|
||||||
app.quit();
|
|
||||||
win = null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
app.on("activate", () => {
|
n.on("activate", () => {
|
||||||
if (BrowserWindow.getAllWindows().length === 0) {
|
i.getAllWindows().length === 0 && l();
|
||||||
createWindow();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
app.whenReady().then(createWindow);
|
n.whenReady().then(l);
|
||||||
export {
|
export {
|
||||||
MAIN_DIST,
|
R as MAIN_DIST,
|
||||||
RENDERER_DIST,
|
r as RENDERER_DIST,
|
||||||
VITE_DEV_SERVER_URL
|
s as VITE_DEV_SERVER_URL
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,22 +1 @@
|
|||||||
"use strict";
|
"use strict";const o=require("electron");o.contextBridge.exposeInMainWorld("ipcRenderer",{on(...e){const[n,r]=e;return o.ipcRenderer.on(n,(t,...c)=>r(t,...c))},off(...e){const[n,...r]=e;return o.ipcRenderer.off(n,...r)},send(...e){const[n,...r]=e;return o.ipcRenderer.send(n,...r)},invoke(...e){const[n,...r]=e;return o.ipcRenderer.invoke(n,...r)}});
|
||||||
const electron = require("electron");
|
|
||||||
electron.contextBridge.exposeInMainWorld("ipcRenderer", {
|
|
||||||
on(...args) {
|
|
||||||
const [channel, listener] = args;
|
|
||||||
return electron.ipcRenderer.on(channel, (event, ...args2) => listener(event, ...args2));
|
|
||||||
},
|
|
||||||
off(...args) {
|
|
||||||
const [channel, ...omit] = args;
|
|
||||||
return electron.ipcRenderer.off(channel, ...omit);
|
|
||||||
},
|
|
||||||
send(...args) {
|
|
||||||
const [channel, ...omit] = args;
|
|
||||||
return electron.ipcRenderer.send(channel, ...omit);
|
|
||||||
},
|
|
||||||
invoke(...args) {
|
|
||||||
const [channel, ...omit] = args;
|
|
||||||
return electron.ipcRenderer.invoke(channel, ...omit);
|
|
||||||
}
|
|
||||||
// You can expose other APTs you need here.
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { app, BrowserWindow } from 'electron'
|
import { app, BrowserWindow } from "electron";
|
||||||
import { createRequire } from 'node:module'
|
// import { createRequire } from 'node:module'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from "node:url";
|
||||||
import path from 'node:path'
|
import path from "node:path";
|
||||||
|
|
||||||
const require = createRequire(import.meta.url)
|
// const require = createRequire(import.meta.url)
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
// The built directory structure
|
// The built directory structure
|
||||||
//
|
//
|
||||||
@@ -15,54 +15,56 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|||||||
// │ │ ├── main.js
|
// │ │ ├── main.js
|
||||||
// │ │ └── preload.mjs
|
// │ │ └── preload.mjs
|
||||||
// │
|
// │
|
||||||
process.env.APP_ROOT = path.join(__dirname, '..')
|
process.env.APP_ROOT = path.join(__dirname, "..");
|
||||||
|
|
||||||
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - Vite@2.x
|
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - Vite@2.x
|
||||||
export const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL']
|
export const VITE_DEV_SERVER_URL = process.env["VITE_DEV_SERVER_URL"];
|
||||||
export const MAIN_DIST = path.join(process.env.APP_ROOT, 'dist-electron')
|
export const MAIN_DIST = path.join(process.env.APP_ROOT, "dist-electron");
|
||||||
export const RENDERER_DIST = path.join(process.env.APP_ROOT, 'dist')
|
export const RENDERER_DIST = path.join(process.env.APP_ROOT, "dist");
|
||||||
|
|
||||||
process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL ? path.join(process.env.APP_ROOT, 'public') : RENDERER_DIST
|
process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL
|
||||||
|
? path.join(process.env.APP_ROOT, "public")
|
||||||
|
: RENDERER_DIST;
|
||||||
|
|
||||||
let win: BrowserWindow | null
|
let win: BrowserWindow | null;
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
icon: path.join(process.env.VITE_PUBLIC, 'electron-vite.svg'),
|
icon: path.join(process.env.VITE_PUBLIC, "electron-vite.svg"),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, 'preload.mjs'),
|
preload: path.join(__dirname, "preload.mjs"),
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
// Test active push message to Renderer-process.
|
// Test active push message to Renderer-process.
|
||||||
win.webContents.on('did-finish-load', () => {
|
win.webContents.on("did-finish-load", () => {
|
||||||
win?.webContents.send('main-process-message', (new Date).toLocaleString())
|
win?.webContents.send("main-process-message", new Date().toLocaleString());
|
||||||
})
|
});
|
||||||
|
|
||||||
if (VITE_DEV_SERVER_URL) {
|
if (VITE_DEV_SERVER_URL) {
|
||||||
win.loadURL(VITE_DEV_SERVER_URL)
|
win.loadURL(VITE_DEV_SERVER_URL);
|
||||||
} else {
|
} else {
|
||||||
// win.loadFile('dist/index.html')
|
// win.loadFile('dist/index.html')
|
||||||
win.loadFile(path.join(RENDERER_DIST, 'index.html'))
|
win.loadFile(path.join(RENDERER_DIST, "index.html"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit when all windows are closed, except on macOS. There, it's common
|
// Quit when all windows are closed, except on macOS. There, it's common
|
||||||
// for applications and their menu bar to stay active until the user quits
|
// for applications and their menu bar to stay active until the user quits
|
||||||
// explicitly with Cmd + Q.
|
// explicitly with Cmd + Q.
|
||||||
app.on('window-all-closed', () => {
|
app.on("window-all-closed", () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== "darwin") {
|
||||||
app.quit()
|
app.quit();
|
||||||
win = null
|
win = null;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on("activate", () => {
|
||||||
// On OS X it's common to re-create a window in the app when the
|
// On OS X it's common to re-create a window in the app when the
|
||||||
// dock icon is clicked and there are no other windows open.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (BrowserWindow.getAllWindows().length === 0) {
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
createWindow()
|
createWindow();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
app.whenReady().then(createWindow)
|
app.whenReady().then(createWindow);
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "bunx --bun vite --open",
|
||||||
"build": "tsc && vite build && electron-builder",
|
"build": "tsc && bunx --bun vite build && electron-builder",
|
||||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
"preview": "vite preview"
|
"preview": "bunx --bun vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user