Skip to content
Open
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
200 changes: 148 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"@types/eslint-plugin-security": "^3.0.0",
"@types/js-cookie": "^3.0.6",
"@types/js-yaml": "^4.0.9",
"@types/node": "^24.2.1",
"@types/psl": "^1.1.3",
"@types/randomatic": "^3.1.5",
"@types/react": "^18.3.3",
Expand All @@ -114,6 +115,7 @@
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.20",
"babel-eslint": "^10.1.0",
"chokidar": "^4.0.3",
"commitlint": "^19.6.1",
"dotenv": "^16.4.7",
"eslint": "^9.21.0",
Expand Down
46 changes: 46 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import dotenv from "dotenv";
import fs from "fs";
import path from "path";
import { defineConfig } from "vite";
import type { Plugin } from "vite";
import { ViteEjsPlugin } from "vite-plugin-ejs";
import mkcert from "vite-plugin-mkcert";
import { viteStaticCopy } from "vite-plugin-static-copy";
Expand All @@ -12,6 +13,50 @@ import { reactVirtualized } from "./fixReactVirtualized";

dotenv.config();

function envWatcherPlugin(): Plugin {
return {
name: "env-watcher",
configureServer(server) {
if (server.config.command !== "serve") return;

const envFiles = [".env", ".env.local", ".env.development", ".env.development.local"];
const envFilePaths = envFiles.map((file) => path.resolve(__dirname, file));

// Initialize file watcher asynchronously
import("chokidar")
.then((chokidar) => {
const watcher = chokidar.default.watch(envFilePaths, {
ignored: /node_modules/,
persistent: true,
});

watcher.on("change", (filePath: string) => {
// eslint-disable-next-line no-console
console.log(`\n🔄 Environment file changed: ${path.relative(__dirname, filePath)}`);
// eslint-disable-next-line no-console
console.log("♻️ Reloading environment variables...\n");

dotenv.config();

server.ws.send({
type: "full-reload",
});
});

server.httpServer?.on("close", () => {
watcher.close();
});

return watcher;
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error("Failed to initialize env file watcher:", error);
});
},
};
}

const packageJsonPath = new URL("package.json", import.meta.url).pathname;
// eslint-disable-next-line security/detect-non-literal-fs-filename
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
Expand Down Expand Up @@ -79,6 +124,7 @@ export default defineConfig({
},
plugins: [
...(process.env.VITE_LOCAL_SSL_CERT === "true" ? [mkcert()] : []),
envWatcherPlugin(), // Add env watcher plugin for development
react(),
ViteEjsPlugin((viteConfig) => ({
env: viteConfig.env,
Expand Down
Loading