Skip to content

Commit

Permalink
Remove .env file and revise vite.config.js
Browse files Browse the repository at this point in the history
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.
23 changes: 8 additions & 15 deletions vite.config.js
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) || '-',
},
});
};

0 comments on commit 0335e77

Please sign in to comment.