mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +02:00
chore(dx/server): basic middleware integration for vite
This commit is contained in:
parent
113d36f5dd
commit
cc474f39d8
@ -41,11 +41,6 @@ export default defineConfig(() => ({
|
|||||||
] as Plugin[],
|
] as Plugin[],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: [
|
alias: [
|
||||||
// Force the use of dist in development mode because upstream ESM is broken (some hybrid between CJS and ESM, will be improved in upcoming versions).
|
|
||||||
{
|
|
||||||
find: "@triliumnext/highlightjs",
|
|
||||||
replacement: resolve(__dirname, "node_modules/@triliumnext/highlightjs/dist")
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
find: "react",
|
find: "react",
|
||||||
replacement: "preact/compat"
|
replacement: "preact/compat"
|
@ -7,7 +7,13 @@
|
|||||||
"better-sqlite3": "12.2.0"
|
"better-sqlite3": "12.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@anthropic-ai/sdk": "0.60.0",
|
||||||
|
"@braintree/sanitize-url": "7.1.1",
|
||||||
"@electron/remote": "2.1.3",
|
"@electron/remote": "2.1.3",
|
||||||
|
"@preact/preset-vite": "2.10.2",
|
||||||
|
"@triliumnext/commons": "workspace:*",
|
||||||
|
"@triliumnext/express-partial-content": "workspace:*",
|
||||||
|
"@triliumnext/turndown-plugin-gfm": "workspace:*",
|
||||||
"@types/archiver": "6.0.3",
|
"@types/archiver": "6.0.3",
|
||||||
"@types/better-sqlite3": "7.6.13",
|
"@types/better-sqlite3": "7.6.13",
|
||||||
"@types/cls-hooked": "4.3.9",
|
"@types/cls-hooked": "4.3.9",
|
||||||
@ -38,16 +44,11 @@
|
|||||||
"@types/turndown": "5.0.5",
|
"@types/turndown": "5.0.5",
|
||||||
"@types/ws": "8.18.1",
|
"@types/ws": "8.18.1",
|
||||||
"@types/xml2js": "0.4.14",
|
"@types/xml2js": "0.4.14",
|
||||||
"express-http-proxy": "2.1.1",
|
|
||||||
"@anthropic-ai/sdk": "0.60.0",
|
|
||||||
"@braintree/sanitize-url": "7.1.1",
|
|
||||||
"@triliumnext/commons": "workspace:*",
|
|
||||||
"@triliumnext/express-partial-content": "workspace:*",
|
|
||||||
"@triliumnext/turndown-plugin-gfm": "workspace:*",
|
|
||||||
"archiver": "7.0.1",
|
"archiver": "7.0.1",
|
||||||
"async-mutex": "0.5.0",
|
"async-mutex": "0.5.0",
|
||||||
"axios": "1.11.0",
|
"axios": "1.11.0",
|
||||||
"bindings": "1.5.0",
|
"bindings": "1.5.0",
|
||||||
|
"bootstrap": "5.3.8",
|
||||||
"chardet": "2.1.0",
|
"chardet": "2.1.0",
|
||||||
"cheerio": "1.1.2",
|
"cheerio": "1.1.2",
|
||||||
"chokidar": "4.0.3",
|
"chokidar": "4.0.3",
|
||||||
@ -64,6 +65,7 @@
|
|||||||
"electron-window-state": "5.0.3",
|
"electron-window-state": "5.0.3",
|
||||||
"escape-html": "1.0.3",
|
"escape-html": "1.0.3",
|
||||||
"express": "5.1.0",
|
"express": "5.1.0",
|
||||||
|
"express-http-proxy": "2.1.1",
|
||||||
"express-openid-connect": "^2.17.1",
|
"express-openid-connect": "^2.17.1",
|
||||||
"express-rate-limit": "8.0.1",
|
"express-rate-limit": "8.0.1",
|
||||||
"express-session": "1.18.2",
|
"express-session": "1.18.2",
|
||||||
@ -105,6 +107,7 @@
|
|||||||
"tmp": "0.2.5",
|
"tmp": "0.2.5",
|
||||||
"turndown": "7.2.1",
|
"turndown": "7.2.1",
|
||||||
"unescape": "1.0.1",
|
"unescape": "1.0.1",
|
||||||
|
"vite": "^7.1.3",
|
||||||
"ws": "8.18.3",
|
"ws": "8.18.3",
|
||||||
"xml2js": "0.6.2",
|
"xml2js": "0.6.2",
|
||||||
"yauzl": "3.2.0"
|
"yauzl": "3.2.0"
|
||||||
@ -361,7 +364,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "cross-env TRILIUM_ENV=dev TRILIUM_DATA_DIR=data TRILIUM_RESOURCE_DIR=src tsx watch ./src/main.ts"
|
"dev": "cross-env TRILIUM_ENV=dev TRILIUM_DATA_DIR=data TRILIUM_RESOURCE_DIR=src tsx watch --ignore '../client/node_modules/.vite-temp' ./src/main.ts"
|
||||||
},
|
},
|
||||||
"main": "./src/main.ts"
|
"main": "./src/main.ts"
|
||||||
}
|
}
|
@ -3,8 +3,9 @@ import path from "path";
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import { getResourceDir, isDev } from "../services/utils.js";
|
import { getResourceDir, isDev } from "../services/utils.js";
|
||||||
import type serveStatic from "serve-static";
|
import type serveStatic from "serve-static";
|
||||||
import proxy from "express-http-proxy";
|
|
||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
|
import { createServer as createViteServer } from "vite";
|
||||||
|
import preact from "@preact/preset-vite";
|
||||||
|
|
||||||
const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOptions<express.Response<unknown, Record<string, unknown>>>) => {
|
const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOptions<express.Response<unknown, Record<string, unknown>>>) => {
|
||||||
if (!isDev) {
|
if (!isDev) {
|
||||||
@ -17,17 +18,24 @@ const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOp
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function register(app: express.Application) {
|
async function register(app: express.Application) {
|
||||||
const srcRoot = path.join(__dirname, "..");
|
const srcRoot = path.join(__dirname, "..", "..");
|
||||||
const resourceDir = getResourceDir();
|
const resourceDir = getResourceDir();
|
||||||
|
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
const publicUrl = process.env.TRILIUM_PUBLIC_SERVER;
|
const vite = await createViteServer({
|
||||||
if (!publicUrl) {
|
base: `/${assetUrlFragment}/`,
|
||||||
throw new Error("Missing TRILIUM_PUBLIC_SERVER");
|
root: path.join(srcRoot, "../client"),
|
||||||
|
plugins: [
|
||||||
|
preact()
|
||||||
|
],
|
||||||
|
define: {
|
||||||
|
"process.env.IS_PREACT": JSON.stringify("true"),
|
||||||
}
|
}
|
||||||
app.use("/" + assetUrlFragment + `/@fs`, proxy(publicUrl, {
|
});
|
||||||
proxyReqPathResolver: (req) => "/" + assetUrlFragment + `/@fs` + req.url
|
app.use(`/${assetUrlFragment}/`, (req, res, next) => {
|
||||||
}));
|
req.url = `/${assetUrlFragment}` + req.url;
|
||||||
|
vite.middlewares(req, res, next);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
const publicDir = path.join(resourceDir, "public");
|
const publicDir = path.join(resourceDir, "public");
|
||||||
if (!existsSync(publicDir)) {
|
if (!existsSync(publicDir)) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import packageJson from "../../package.json" with { type: "json" };
|
import packageJson from "../../package.json" with { type: "json" };
|
||||||
import { isDev } from "./utils";
|
|
||||||
|
|
||||||
export const assetUrlFragment = `assets/v${packageJson.version}`;
|
export const assetUrlFragment = `assets/v${packageJson.version}`;
|
||||||
const assetPath = isDev ? `http://localhost:4200/${assetUrlFragment}` : assetUrlFragment;
|
const assetPath = assetUrlFragment;
|
||||||
|
|
||||||
export default assetPath;
|
export default assetPath;
|
||||||
|
947
pnpm-lock.yaml
generated
947
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user