vite.config.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/ui": fileURLToPath(new URL("../../packages/ui/src/index.ts", import.meta.url)),
  34. "@nengine/core-schema": fileURLToPath(new URL("../../packages/core/src/schema/index.ts", import.meta.url)),
  35. "@nengine/core-systems": fileURLToPath(new URL("../../packages/core/src/systems/index.ts", import.meta.url)),
  36. ...shimAliases,
  37. },
  38. },
  39. build: {
  40. outDir: "dist/renderer",
  41. emptyOutDir: true,
  42. rollupOptions: {
  43. input: fileURLToPath(new URL("./index.html", import.meta.url)),
  44. },
  45. },
  46. test: {
  47. include: ["test/**/*.test.ts"],
  48. environment: "node",
  49. testTimeout: 20000,
  50. },
  51. };
  52. });