mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-24 12:24:01 +02:00
The browser host now stores data through yaak-models compiled to wasm — the same queries, migrations, cascade rules, duplicate naming and first-run bootstrap the desktop and CLI use — instead of a TypeScript port of them. - crates/yaak-web: the wasm crate. boot() registers an IndexedDB-backed VFS and calls init_standalone; rpc(cmd, payload, label) answers the models_* commands via ClientDb and returns the model_writes it caused; blob get/put through blob_manager. Built like yaak-templates (pkg/ committed); the build script keeps pkg/ and says so when no wasm-capable clang is present, so a desktop bootstrap never depends on one. - models_ops moves from crates/yaak into yaak-models so the wasm crate can use it without the send engine. - The database lives in a SharedWorker (packages/platform/src/web/worker.ts): one process holds the data and pushes writes to every tab, as on the desktop. Where SharedWorker is missing or its script cannot be fetched, a dedicated worker guarded by a Web Lock takes over and a second tab is told so. The worker imports the wasm lazily so a tab's connect is answered instantly; the tab reconnects if it isn't. - packages/platform/src/web loses models.ts, schema.ts, db.ts and the BroadcastChannel; commands.ts forwards model commands to the worker and keeps the fixed answers and refusals. Verified in Chrome, dev and production builds: bootstrap, CRUD across every model type, serde defaults, engine-format ids, Rust copy naming, folder cascade with per-descendant events, single-event workspace delete, reload persistence, two tabs coherent, Send declined with a toast, 8/8 reloads rendering in ~100 ms.
94 lines
3.1 KiB
TypeScript
94 lines
3.1 KiB
TypeScript
// @ts-ignore
|
|
import { tanstackRouter } from "@tanstack/router-plugin/vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import { createRequire } from "node:module";
|
|
import path from "node:path";
|
|
import { defineConfig, normalizePath } from "vite-plus";
|
|
import { viteStaticCopy } from "vite-plugin-static-copy";
|
|
import svgr from "vite-plugin-svgr";
|
|
import topLevelAwait from "vite-plugin-top-level-await";
|
|
import wasm from "vite-plugin-wasm";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const cMapsDir = normalizePath(
|
|
path.join(path.dirname(require.resolve("pdfjs-dist/package.json")), "cmaps"),
|
|
);
|
|
const standardFontsDir = normalizePath(
|
|
path.join(path.dirname(require.resolve("pdfjs-dist/package.json")), "standard_fonts"),
|
|
);
|
|
|
|
/**
|
|
* Which host the platform package installs. `web` builds Yaak to run in a plain
|
|
* browser tab, with its own IndexedDB store instead of the Rust engine; anything
|
|
* else builds the desktop app exactly as before.
|
|
*/
|
|
const yaakTarget = process.env.YAAK_TARGET === "web" ? "web" : "desktop";
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig(async () => {
|
|
return {
|
|
resolve: {
|
|
alias:
|
|
yaakTarget === "web"
|
|
? {
|
|
// Resolve the platform package to its browser entry, so a web
|
|
// build never pulls `@tauri-apps/*` into the graph at all. A
|
|
// build-time branch inside the package would not manage that:
|
|
// the dead branch folds away, but the imports it guarded stay.
|
|
"@yaakapp-internal/platform": path.resolve(
|
|
import.meta.dirname,
|
|
"../../packages/platform/src/index.web.ts",
|
|
),
|
|
}
|
|
: {},
|
|
},
|
|
// The browser host runs the model layer in a worker; that bundle needs the
|
|
// same wasm and top-level-await handling as the main one.
|
|
worker: {
|
|
format: "es" as const,
|
|
plugins: () => [wasm(), topLevelAwait()],
|
|
},
|
|
plugins: [
|
|
wasm(),
|
|
tanstackRouter({
|
|
target: "react",
|
|
routesDirectory: "./routes",
|
|
generatedRouteTree: "./routeTree.gen.ts",
|
|
autoCodeSplitting: true,
|
|
}),
|
|
svgr(),
|
|
react(),
|
|
topLevelAwait(),
|
|
viteStaticCopy({
|
|
targets: [
|
|
{ src: cMapsDir, dest: "" },
|
|
{ src: standardFontsDir, dest: "" },
|
|
],
|
|
}),
|
|
],
|
|
build: {
|
|
target: "esnext",
|
|
sourcemap: true,
|
|
outDir: "../../dist/apps/yaak-client",
|
|
emptyOutDir: true,
|
|
rolldownOptions: {
|
|
output: {
|
|
// Make chunk names readable
|
|
chunkFileNames: "assets/chunk-[name]-[hash].js",
|
|
entryFileNames: "assets/entry-[name]-[hash].js",
|
|
assetFileNames: "assets/asset-[name]-[hash][extname]",
|
|
// Vite-Plus/Rolldown 0.1.20 can emit a stale style-mod export when
|
|
// top-level var rewriting combines with OXC minification.
|
|
topLevelVar: false,
|
|
},
|
|
},
|
|
},
|
|
clearScreen: false,
|
|
server: {
|
|
port: parseInt(process.env.YAAK_CLIENT_DEV_PORT ?? process.env.YAAK_DEV_PORT ?? "1420", 10),
|
|
strictPort: true,
|
|
},
|
|
envPrefix: ["VITE_", "TAURI_"],
|
|
};
|
|
});
|