Skip to content

Commit

Permalink
Added env variable to enable or disable vite docker config
Browse files Browse the repository at this point in the history
  • Loading branch information
KarmineSH committed Oct 2, 2024
1 parent 5339c90 commit f5ca2a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions frontend/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ VITE_ENV=local
VITE_VERSION_NUMBER=v0.0.1
VITE_API_URL=<API_URL>
VITE_GA_TRACKING_ID=<GA_TRACKING_ID>
VITE_DOCKER=false
21 changes: 10 additions & 11 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig, loadEnv } from "vite";
import { defineConfig, loadEnv, ServerOptions } from "vite";
import react from "@vitejs/plugin-react";
import { pigment } from "@pigment-css/vite-plugin";
import theme from "./src/themes/theme";
Expand All @@ -7,6 +7,14 @@ import path from "path";
export default ({ mode }: { mode: string }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };

const serverOptions: ServerOptions = {
port: Number(process.env.VITE_PORT),
};
if (process.env.VITE_DOCKER === "true") {
serverOptions.host = true;
serverOptions.watch = { usePolling: true };
}

return defineConfig({
plugins: [
react(),
Expand All @@ -18,16 +26,7 @@ export default ({ mode }: { mode: string }) => {
build: {
sourcemap: process.env.VITE_GENERATE_SOURCEMAP === "true",
},
server: {
port: Number(process.env.VITE_PORT),
// DOCKER SETUP
// add the next lines so that it works on docker
// host: true,
// add the next lines if you're using windows and hot reload doesn't work
// watch: {
// usePolling: true,
// },
},
server: serverOptions,
define: {
__ENV__: JSON.stringify(process.env.VITE_ENV),
__API_URL__: JSON.stringify(process.env.VITE_API_URL),
Expand Down

0 comments on commit f5ca2a0

Please sign in to comment.