react-router.config.ts 1020 B

1234567891011121314151617181920212223242526272829303132333435
  1. import type { Config } from "@react-router/dev/config";
  2. /**
  3. * This script is used to unpack the client directory from the frontend build directory.
  4. * Remix SPA mode builds the client directory into the build directory. This function
  5. * moves the contents of the client directory to the build directory and then removes the
  6. * client directory.
  7. *
  8. * This script is used in the buildEnd function of the Vite config.
  9. */
  10. const unpackClientDirectory = async () => {
  11. const fs = await import("fs");
  12. const path = await import("path");
  13. const buildDir = path.resolve(__dirname, "build");
  14. const clientDir = path.resolve(buildDir, "client");
  15. const files = await fs.promises.readdir(clientDir);
  16. await Promise.all(
  17. files.map((file) =>
  18. fs.promises.rename(
  19. path.resolve(clientDir, file),
  20. path.resolve(buildDir, file),
  21. ),
  22. ),
  23. );
  24. await fs.promises.rmdir(clientDir);
  25. };
  26. export default {
  27. appDirectory: "src",
  28. buildEnd: unpackClientDirectory,
  29. ssr: false,
  30. } satisfies Config;