feat(vite.config): Allowed Hosts Defined Through Env Variable

This commit is contained in:
x
2025-05-02 14:45:44 -04:00
parent 0faa8f4bb0
commit e43f583eb6

View File

@@ -1,6 +1,6 @@
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";
import react from "@vitejs/plugin-react-swc";
import { defineConfig, PluginOption } from "vite";
import { defineConfig, loadEnv, PluginOption } from "vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import topLevelAwait from "vite-plugin-top-level-await";
import wasm from "vite-plugin-wasm";
@@ -20,8 +20,13 @@ const virtualRouteFileChangeReloadPlugin: PluginOption = {
};
// https://vite.dev/config/
export default defineConfig({
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
const allowedHosts = env.VITE_ALLOWED_HOSTS?.split(",") ?? [];
return {
server: {
allowedHosts,
host: true,
port: 3000
// proxy: {
@@ -48,4 +53,5 @@ export default defineConfig({
react(),
virtualRouteFileChangeReloadPlugin
]
};
});