|
@@ -1,12 +1,37 @@
|
|
|
import path from "path"
|
|
import path from "path"
|
|
|
|
|
+import fs from "fs"
|
|
|
|
|
|
|
|
import { defineConfig } from "vite"
|
|
import { defineConfig } from "vite"
|
|
|
import react from "@vitejs/plugin-react"
|
|
import react from "@vitejs/plugin-react"
|
|
|
import tailwindcss from "@tailwindcss/vite"
|
|
import tailwindcss from "@tailwindcss/vite"
|
|
|
|
|
|
|
|
|
|
+// Custom plugin to write the server port to a file
|
|
|
|
|
+const writePortToFile = () => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ name: "write-port-to-file",
|
|
|
|
|
+ configureServer(server) {
|
|
|
|
|
+ // Write the port to a file when the server starts
|
|
|
|
|
+ server.httpServer?.once("listening", () => {
|
|
|
|
|
+ const address = server.httpServer.address()
|
|
|
|
|
+ const port = typeof address === "object" && address ? address.port : null
|
|
|
|
|
+
|
|
|
|
|
+ if (port) {
|
|
|
|
|
+ // Write to a file in the project root
|
|
|
|
|
+ const portFilePath = path.resolve(__dirname, "../.vite-port")
|
|
|
|
|
+ fs.writeFileSync(portFilePath, port.toString())
|
|
|
|
|
+ console.log(`[Vite Plugin] Server started on port ${port}`)
|
|
|
|
|
+ console.log(`[Vite Plugin] Port information written to ${portFilePath}`)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.warn("[Vite Plugin] Could not determine server port")
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// https://vitejs.dev/config/
|
|
// https://vitejs.dev/config/
|
|
|
export default defineConfig({
|
|
export default defineConfig({
|
|
|
- plugins: [react(), tailwindcss()],
|
|
|
|
|
|
|
+ plugins: [react(), tailwindcss(), writePortToFile()],
|
|
|
resolve: {
|
|
resolve: {
|
|
|
alias: {
|
|
alias: {
|
|
|
"@": path.resolve(__dirname, "./src"),
|
|
"@": path.resolve(__dirname, "./src"),
|