Enhance Vite configuration to load environment variables
- Refactored Vite configuration to load environment variables explicitly based on the current mode - Added support for additional environment variables: VITE_DAEMON_SOCKET, VITE_API_BASE_URL, VITE_CHAT_WS_URL, and VITE_SOCKET_IO_URL - Improved clarity and maintainability of the configuration structure
This commit is contained in:
@@ -1,17 +1,34 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig, loadEnv } from 'vite';
|
||||||
import vue from '@vitejs/plugin-vue';
|
import vue from '@vitejs/plugin-vue';
|
||||||
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
|
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
|
||||||
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
|
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
|
// Lade Umgebungsvariablen explizit
|
||||||
|
const env = loadEnv(mode, process.cwd(), '');
|
||||||
|
|
||||||
|
return {
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
define: {
|
define: {
|
||||||
// Explizit Produktionsumgebung setzen
|
// Explizit Produktionsumgebung setzen
|
||||||
__DEV__: false,
|
__DEV__: false,
|
||||||
'import.meta.env.DEV': false,
|
'import.meta.env.DEV': false,
|
||||||
'import.meta.env.PROD': true,
|
'import.meta.env.PROD': true,
|
||||||
'import.meta.env.MODE': '"production"'
|
'import.meta.env.MODE': '"production"',
|
||||||
|
// Stelle sicher, dass Umgebungsvariablen aus .env.production geladen werden
|
||||||
|
...(env.VITE_DAEMON_SOCKET && {
|
||||||
|
'import.meta.env.VITE_DAEMON_SOCKET': JSON.stringify(env.VITE_DAEMON_SOCKET)
|
||||||
|
}),
|
||||||
|
...(env.VITE_API_BASE_URL && {
|
||||||
|
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL)
|
||||||
|
}),
|
||||||
|
...(env.VITE_CHAT_WS_URL && {
|
||||||
|
'import.meta.env.VITE_CHAT_WS_URL': JSON.stringify(env.VITE_CHAT_WS_URL)
|
||||||
|
}),
|
||||||
|
...(env.VITE_SOCKET_IO_URL && {
|
||||||
|
'import.meta.env.VITE_SOCKET_IO_URL': JSON.stringify(env.VITE_SOCKET_IO_URL)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
esbuildOptions: {
|
esbuildOptions: {
|
||||||
@@ -31,4 +48,5 @@ export default defineConfig({
|
|||||||
assert: 'assert',
|
assert: 'assert',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
};
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user