Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ docs/_site/

#Logging
logs

# Vite development
.vite-port
21 changes: 20 additions & 1 deletion src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,26 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
}

private async getHMRHtmlContent(webview: vscode.Webview): Promise<string> {
const localPort = "5173"
// Try to read the port from the file
let localPort = "5173" // Default fallback
try {
const fs = require("fs")
const path = require("path")
const portFilePath = path.resolve(__dirname, "../.vite-port")

if (fs.existsSync(portFilePath)) {
localPort = fs.readFileSync(portFilePath, "utf8").trim()
console.log(`[ClineProvider:Vite] Using Vite server port from ${portFilePath}: ${localPort}`)
} else {
console.log(
`[ClineProvider:Vite] Port file not found at ${portFilePath}, using default port: ${localPort}`,
)
}
} catch (err) {
console.error("[ClineProvider:Vite] Failed to read Vite port file:", err)
// Continue with default port if file reading fails
}

const localServerUrl = `localhost:${localPort}`

// Check if local dev server is running.
Expand Down
27 changes: 26 additions & 1 deletion webview-ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
import path from "path"
import fs from "fs"

import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
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/
export default defineConfig({
plugins: [react(), tailwindcss()],
plugins: [react(), tailwindcss(), writePortToFile()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
Expand Down