* Fix CLINE_ENVIRONMENT configuration not being passed to webview ## Problem The CLINE_ENVIRONMENT configuration set in launch.json was not being properly passed to the webview, causing the webview to break when trying to access environment-specific configurations. This resulted in: Webview using incorrect API URLs (always defaulting to production) Broken authentication flows in development/staging environments Inconsistent behavior between the main extension and webview components ## Root Cause The issue occurred because: Duplicate Configuration Logic: The webview had its own separate config.ts file that was trying to read process.env.CLINE_ENVIRONMENT directly Environment Variable Propagation: While Vite was configured to pass CLINE_ENVIRONMENT to the build process, the webview's runtime code couldn't access this environment variable properly Configuration Mismatch: The main extension and webview were using different configuration sources, leading to inconsistent environment settings * fix credit uri * replace apiBaseUrl with appBaseUrl * local option * fallback changed to app * change to app url * merge fixes --------- Co-authored-by: 0xtoshii <94262432+0xToshii@users.noreply.github.com>
82 lines
2.0 KiB
TypeScript
82 lines
2.0 KiB
TypeScript
/// <reference types="vitest/config" />
|
|
|
|
import { defineConfig, ViteDevServer, type Plugin } from "vite"
|
|
import tailwindcss from "@tailwindcss/vite"
|
|
import react from "@vitejs/plugin-react-swc"
|
|
import { resolve } from "path"
|
|
import { writeFileSync } from "node:fs"
|
|
|
|
// Custom plugin to write the server port to a file
|
|
const writePortToFile = (): Plugin => {
|
|
return {
|
|
name: "write-port-to-file",
|
|
configureServer(server: ViteDevServer) {
|
|
server.httpServer?.once("listening", () => {
|
|
const address = server.httpServer?.address()
|
|
const port = typeof address === "object" && address ? address.port : null
|
|
|
|
if (port) {
|
|
const portFilePath = resolve(__dirname, ".vite-port")
|
|
writeFileSync(portFilePath, port.toString())
|
|
} else {
|
|
console.warn("[writePortToFile] Could not determine server port")
|
|
}
|
|
})
|
|
},
|
|
}
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [react(), tailwindcss(), writePortToFile()],
|
|
test: {
|
|
environment: "jsdom",
|
|
globals: true,
|
|
setupFiles: ["./src/setupTests.ts"],
|
|
coverage: {
|
|
provider: "v8",
|
|
reportOnFailure: true,
|
|
},
|
|
},
|
|
build: {
|
|
outDir: "build",
|
|
reportCompressedSize: false,
|
|
rollupOptions: {
|
|
output: {
|
|
inlineDynamicImports: true,
|
|
entryFileNames: `assets/[name].js`,
|
|
chunkFileNames: `assets/[name].js`,
|
|
assetFileNames: `assets/[name].[ext]`,
|
|
},
|
|
},
|
|
chunkSizeWarningLimit: 100000,
|
|
},
|
|
server: {
|
|
port: 25463,
|
|
hmr: {
|
|
host: "localhost",
|
|
protocol: "ws",
|
|
},
|
|
cors: {
|
|
origin: "*",
|
|
methods: "*",
|
|
allowedHeaders: "*",
|
|
},
|
|
},
|
|
define: {
|
|
"process.env": {
|
|
NODE_ENV: JSON.stringify(process.env.IS_DEV ? "development" : "production"),
|
|
IS_DEV: JSON.stringify(process.env.IS_DEV),
|
|
IS_TEST: JSON.stringify(process.env.IS_TEST),
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
"@": resolve(__dirname, "./src"),
|
|
"@components": resolve(__dirname, "./src/components"),
|
|
"@context": resolve(__dirname, "./src/context"),
|
|
"@shared": resolve(__dirname, "../src/shared"),
|
|
"@utils": resolve(__dirname, "./src/utils"),
|
|
},
|
|
},
|
|
})
|