vite.config.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { fileURLToPath, URL } from "node:url";
  2. import { defineConfig } from "vitest/config";
  3. // The editor renderer is its own Vite app (root = apps/editor, own index.html).
  4. // The main process loads the built renderer from dist/renderer/ over a local
  5. // HTTP server (see src/main.ts), so no fs-shim middleware is needed here.
  6. // `@nengine/core` aliases to source for dev/test speed; E1 used core TYPES only,
  7. // E2 (map editing) also needs runtime `mapSchema`/`UNWALKABLE_TILES`. The full
  8. // core barrel is NOT browser-safe (loader/mods import node:fs) — E2–E4 import it
  9. // via two editor-only synthetic facets that alias core's PURE source modules
  10. // (schema/ and systems/ — no node builtins): `@nengine/core-schema` and
  11. // `@nengine/core-systems` (mirrored by "paths" in tsconfig.renderer.json). E5
  12. // (playtest) brings the FULL `@nengine/core` barrel into the renderer and
  13. // neutralizes its node:fs/node:path/node:url imports with the dev-app-proven
  14. // in-memory shim aliases (src/shim/ — bundle mode performs ZERO fs calls at
  15. // runtime, D30/D36, so the stubs are never invoked). `@nengine/render` (PixiJS
  16. // viewport + connectLocal) is browser-safe and aliased to source like core.
  17. // The node shim aliases are scoped to non-test builds: vitest (mode "test")
  18. // runs in Node where the real `node:*` builtins must stay intact (tests use
  19. // mkdtemp/writeFile on real tmp dirs).
  20. export default defineConfig(({ mode }) => {
  21. const shimAliases: Record<string, string> = mode === "test" ? {} : {
  22. "node:fs/promises": fileURLToPath(new URL("./src/shim/fs-promises.ts", import.meta.url)),
  23. "node:fs": fileURLToPath(new URL("./src/shim/fs.ts", import.meta.url)),
  24. "node:path": fileURLToPath(new URL("./src/shim/path.ts", import.meta.url)),
  25. "node:url": fileURLToPath(new URL("./src/shim/url.ts", import.meta.url)),
  26. };
  27. return {
  28. root: fileURLToPath(new URL(".", import.meta.url)),
  29. resolve: {
  30. alias: {
  31. "@nengine/core": fileURLToPath(new URL("../../packages/core/src/index.ts", import.meta.url)),
  32. "@nengine/render": fileURLToPath(new URL("../../packages/render/src/index.ts", import.meta.url)),
  33. "@nengine/core-schema": fileURLToPath(new URL("../../packages/core/src/schema/index.ts", import.meta.url)),
  34. "@nengine/core-systems": fileURLToPath(new URL("../../packages/core/src/systems/index.ts", import.meta.url)),
  35. ...shimAliases,
  36. },
  37. },
  38. build: {
  39. outDir: "dist/renderer",
  40. emptyOutDir: true,
  41. rollupOptions: {
  42. input: fileURLToPath(new URL("./index.html", import.meta.url)),
  43. },
  44. },
  45. test: {
  46. include: ["test/**/*.test.ts"],
  47. environment: "node",
  48. testTimeout: 20000,
  49. },
  50. };
  51. });