-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove .env file and revise vite.config.js
The revision involves deleting the .env file from the repository and updating vite.config.js to enhance the security. Now, environment variables are directly accessed through process.env, which prevents potential exposure of sensitive information.
- Loading branch information
THORSTEN SCHMINKEL
committed
Feb 12, 2024
1 parent
b1694a8
commit 0335e77
Showing
1 changed file
with
8 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,26 @@ | ||
import { defineConfig, loadEnv } from 'vite'; | ||
import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); // load env vars from .env file | ||
// load env vars from .env file or from the environment | ||
dotenv.config(); | ||
|
||
// This function is exported for Vite to use as configuration | ||
export default ({ mode }) => { | ||
|
||
console.log("### (vite.config.js) process.env: ", process.env); | ||
|
||
// Load app-level env vars specific to the current mode | ||
const env = loadEnv(mode, process.cwd()); | ||
|
||
console.log("### (vite.config.js) mode: ", mode); | ||
console.log("### (vite.config.js) Loaded env vars: ", env); | ||
|
||
return defineConfig({ | ||
// Use the VITE_BASE_PATH environment variable, fallback to '/' if not defined | ||
base: env.VITE_BASE_PATH || '/', | ||
base: JSON.stringify(process.env.VITE_BASE_PATH) || '/', | ||
|
||
// Include plugins needed by the application, for example, react | ||
plugins: [react()], | ||
|
||
// Define global constants which can be replaced at build time, see main.jsx | ||
define: { | ||
__VITE_BASE_PATH__: JSON.stringify(env.VITE_BASE_PATH), | ||
__VITE_STRIPE_PUBLIC_KEY__: JSON.stringify(env.VITE_STRIPE_PUBLIC_KEY), | ||
__VITE_STRIPE_SUCCESS_URL__: JSON.stringify(env.VITE_STRIPE_SUCCESS_URL), | ||
__VITE_STRIPE_CANCEL_URL__: JSON.stringify(env.VITE_STRIPE_CANCEL_URL), | ||
__VITE_BASE_PATH__: JSON.stringify(process.env.VITE_BASE_PATH) || '-', | ||
__VITE_STRIPE_PUBLIC_KEY__: JSON.stringify(process.env.VITE_STRIPE_PUBLIC_KEY) || '-', | ||
__VITE_STRIPE_SUCCESS_URL__: JSON.stringify(process.env.VITE_STRIPE_SUCCESS_URL) || '-', | ||
__VITE_STRIPE_CANCEL_URL__: JSON.stringify(process.env.VITE_STRIPE_CANCEL_URL) || '-', | ||
}, | ||
}); | ||
}; |