vite.config.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { resolve } from "path"
  2. import fs from "fs"
  3. import { defineConfig } from "vite"
  4. import react from "@vitejs/plugin-react"
  5. import tailwindcss from "@tailwindcss/vite"
  6. // Custom plugin to write the server port to a file
  7. const writePortToFile = () => {
  8. return {
  9. name: "write-port-to-file",
  10. configureServer(server) {
  11. // Write the port to a file when the server starts
  12. server.httpServer?.once("listening", () => {
  13. const address = server.httpServer.address()
  14. const port = typeof address === "object" && address ? address.port : null
  15. if (port) {
  16. // Write to a file in the project root
  17. const portFilePath = resolve(__dirname, "../.vite-port")
  18. fs.writeFileSync(portFilePath, port.toString())
  19. console.log(`[Vite Plugin] Server started on port ${port}`)
  20. console.log(`[Vite Plugin] Port information written to ${portFilePath}`)
  21. } else {
  22. console.warn("[Vite Plugin] Could not determine server port")
  23. }
  24. })
  25. },
  26. }
  27. }
  28. // https://vitejs.dev/config/
  29. export default defineConfig({
  30. plugins: [react(), tailwindcss(), writePortToFile()],
  31. resolve: {
  32. alias: {
  33. "@": resolve(__dirname, "./src"),
  34. "@src": resolve(__dirname, "./src"),
  35. "@roo": resolve(__dirname, "../src"),
  36. },
  37. },
  38. build: {
  39. outDir: "build",
  40. reportCompressedSize: false,
  41. rollupOptions: {
  42. output: {
  43. entryFileNames: `assets/[name].js`,
  44. chunkFileNames: `assets/[name].js`,
  45. assetFileNames: `assets/[name].[ext]`,
  46. },
  47. },
  48. },
  49. server: {
  50. hmr: {
  51. host: "localhost",
  52. protocol: "ws",
  53. },
  54. cors: {
  55. origin: "*",
  56. methods: "*",
  57. allowedHeaders: "*",
  58. },
  59. },
  60. define: {
  61. "process.platform": JSON.stringify(process.platform),
  62. "process.env.VSCODE_TEXTMATE_DEBUG": JSON.stringify(process.env.VSCODE_TEXTMATE_DEBUG),
  63. },
  64. })