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