/ proof-of-concept / plate-dynamics-lab
Sign in
proof-of-concept / plate-dynamics-lab
plate-dynamics-lab / vite.shared.ts
19 lines · 775 BBlameHistoryRaw
1import { readFileSync } from "node:fs";
2import { fileURLToPath } from "node:url";
3import path from "node:path";
5/**
6 * Vite `define` entries every host needs to run numbl in the browser:
7 * numbl reads `process` in a few guarded places, and the lab reports numbl's
8 * package version (its `exports` map does not expose package.json to imports).
9 */
10export function numblDefine(): Record<string, string> {
11 const entry = fileURLToPath(import.meta.resolve("numbl"));
12 const pkgPath = path.join(path.dirname(entry), "..", "package.json");
13 const version = (JSON.parse(readFileSync(pkgPath, "utf8")) as { version: string }).version;
14 return {
15 "process.platform": JSON.stringify("browser"),
16 "process.env": "{}",
17 __NUMBL_VERSION__: JSON.stringify(version),
18 };
↑↓ move↵openescclose