Lines 130-170javascript
130 res.end("not found");
134 if (url.pathname.startsWith("/api/")) {
135 handle(req, res, url);
138 serveClient(req, res, url);
143 // -- production: prebuilt static client + bundled server, no Vite ---------- //
144 const distClient = join(pkgRoot, "dist/client");
145 const distIndex = join(distClient, "index.html");
146 if (!fs.existsSync(distIndex)) {
147 console.error(`yamlover: production build missing at ${distClient}`);
148 console.error(" run `npm run build` in tools/server first.");
151 ({ createHandlers } = await import(pathToFileURL(join(pkgRoot, "dist/server.js")).href));
152 serveClient = (req, res, url) => serveStatic(res, url, distClient, distIndex);
MediumDynamic Require
Package source references dynamic require/import behavior.
bin/yamlover.jsView on unpkg · L150 154 // -- live: Vite middleware + ssrLoadModule (repo checkout) ----------------- //
155 // Vite and its plugin are DYNAMIC imports so production mode (where they are not
156 // installed) never tries to resolve them.
157 const { createServer } = await import("vite");
158 const { default: react } = await import("@vitejs/plugin-react");
160 // Resolve react/react-dom as *this package* sees them, and alias Vite to those
161 // exact copies, so the SPA never picks up a stale React from a parent
162 // node_modules (the "does not provide an export named 'createRoot'" failure).
163 const reactAlias = {};
164 // Directories Vite is allowed to serve over `/@fs`. Start with this package; add
165 // the node_modules that actually holds the heavy deps — under `npx` they hoist to
166 // a `_npx/<hash>/node_modules` outside `pkgRoot` and Vite's default root detection
167 // misses it, so a raw asset (notably pdf.js's worker) 404s to index.html.
168 const fsAllow = [pkgRoot];
170 const req = createRequire(join(pkgRoot, "package.json"));