132 lines
3.6 KiB
JavaScript
132 lines
3.6 KiB
JavaScript
const { defineConfig } = require('vite')
|
|
const vue = require('@vitejs/plugin-vue')
|
|
const path = require('path')
|
|
|
|
// Configuration par environnement
|
|
const getEnvironmentConfig = (mode) => {
|
|
const configs = {
|
|
local: {
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 5173,
|
|
allowedHosts: ['localhost', '127.0.0.1'],
|
|
proxy: {
|
|
'/api': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true,
|
|
secure: false
|
|
},
|
|
'/uploads': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true,
|
|
secure: false
|
|
}
|
|
}
|
|
},
|
|
define: {
|
|
__ENVIRONMENT__: '"local"'
|
|
}
|
|
},
|
|
development: {
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 5173,
|
|
allowedHosts: ['dev.lediscord.com', 'localhost'],
|
|
// Pas de proxy en développement car l'API est externe (https://api-dev.lediscord.com)
|
|
// Le proxy n'est nécessaire que pour l'environnement local
|
|
},
|
|
define: {
|
|
__ENVIRONMENT__: '"development"'
|
|
}
|
|
},
|
|
production: {
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 5173,
|
|
allowedHosts: ['lediscord.com', 'www.lediscord.com'],
|
|
proxy: {
|
|
'/api': {
|
|
target: 'https://api.lediscord.com',
|
|
changeOrigin: true,
|
|
secure: true
|
|
},
|
|
'/uploads': {
|
|
target: 'https://api.lediscord.com',
|
|
changeOrigin: true,
|
|
secure: true
|
|
}
|
|
}
|
|
},
|
|
define: {
|
|
__ENVIRONMENT__: '"production"'
|
|
}
|
|
}
|
|
}
|
|
|
|
return configs[mode] || configs.local
|
|
}
|
|
|
|
module.exports = defineConfig(({ command, mode }) => {
|
|
// Détecter l'environnement
|
|
const env = process.env.NODE_ENV || mode || 'local'
|
|
const envConfig = getEnvironmentConfig(env)
|
|
|
|
console.log(`🚀 Configuration Vite pour l'environnement: ${env.toUpperCase()}`)
|
|
console.log(`🔧 Variables d'environnement:`, {
|
|
NODE_ENV: process.env.NODE_ENV,
|
|
VITE_ENVIRONMENT: process.env.VITE_ENVIRONMENT,
|
|
VITE_API_URL: process.env.VITE_API_URL,
|
|
VITE_APP_URL: process.env.VITE_APP_URL
|
|
})
|
|
|
|
return {
|
|
plugins: [vue()],
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src')
|
|
}
|
|
},
|
|
|
|
// Configuration du serveur selon l'environnement
|
|
server: envConfig.server,
|
|
|
|
// Configuration pour la production
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: {
|
|
vendor: ['vue', 'vue-router', 'pinia'],
|
|
utils: ['axios', 'date-fns']
|
|
}
|
|
}
|
|
},
|
|
// Optimisations de production
|
|
minify: env === 'production' ? 'terser' : false,
|
|
sourcemap: env !== 'production',
|
|
// Variables d'environnement
|
|
define: envConfig.define
|
|
},
|
|
|
|
// Configuration des variables d'environnement
|
|
define: {
|
|
...envConfig.define,
|
|
__BUILD_TIME__: JSON.stringify(new Date().toISOString()),
|
|
// Forcer les variables d'environnement
|
|
'import.meta.env.VITE_ENVIRONMENT': JSON.stringify(process.env.VITE_ENVIRONMENT || env),
|
|
'import.meta.env.VITE_API_URL': JSON.stringify(process.env.VITE_API_URL),
|
|
'import.meta.env.VITE_APP_URL': JSON.stringify(process.env.VITE_APP_URL)
|
|
},
|
|
|
|
// Optimisations selon l'environnement
|
|
optimizeDeps: {
|
|
include: ['vue', 'vue-router', 'pinia', 'axios']
|
|
},
|
|
|
|
// Configuration des assets
|
|
assetsInclude: ['**/*.png', '**/*.jpg', '**/*.jpeg', '**/*.gif', '**/*.svg', '**/*.mp4', '**/*.webm'],
|
|
|
|
// Configuration du mode
|
|
mode: env === 'production' ? 'production' : 'development'
|
|
}
|
|
})
|