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,19 +1,36 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { defineConfig, loadEnv } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
|
||||
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
|
||||
import path from 'path';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
define: {
|
||||
// Explizit Produktionsumgebung setzen
|
||||
__DEV__: false,
|
||||
'import.meta.env.DEV': false,
|
||||
'import.meta.env.PROD': true,
|
||||
'import.meta.env.MODE': '"production"'
|
||||
},
|
||||
optimizeDeps: {
|
||||
export default defineConfig(({ mode }) => {
|
||||
// Lade Umgebungsvariablen explizit
|
||||
const env = loadEnv(mode, process.cwd(), '');
|
||||
|
||||
return {
|
||||
plugins: [vue()],
|
||||
define: {
|
||||
// Explizit Produktionsumgebung setzen
|
||||
__DEV__: false,
|
||||
'import.meta.env.DEV': false,
|
||||
'import.meta.env.PROD': true,
|
||||
'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: {
|
||||
esbuildOptions: {
|
||||
plugins: [
|
||||
NodeGlobalsPolyfillPlugin({
|
||||
@@ -23,12 +40,13 @@ export default defineConfig({
|
||||
]
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
stream: 'stream-browserify',
|
||||
util: 'util',
|
||||
assert: 'assert',
|
||||
}
|
||||
},
|
||||
})
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
stream: 'stream-browserify',
|
||||
util: 'util',
|
||||
assert: 'assert',
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user