Parametrize configurations¡
This commit is contained in:
@@ -1,14 +1,34 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { defineConfig, loadEnv } from 'vite';
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
export default defineConfig({
|
||||
base: '/taller/',
|
||||
plugins: [svelte()],
|
||||
test: {
|
||||
environment: 'jsdom',
|
||||
globals: true,
|
||||
},
|
||||
server: {
|
||||
port: 5173,
|
||||
},
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), 'VITE_');
|
||||
const basePath = '/taller/';
|
||||
const defaultApiBase = `${basePath.replace(/\/$/, '')}/api`;
|
||||
const apiBase = (env.VITE_API_BASE || defaultApiBase).replace(/\/$/, '');
|
||||
const apiProxyPath = apiBase.startsWith('http') ? null : apiBase;
|
||||
|
||||
return {
|
||||
base: basePath,
|
||||
plugins: [svelte()],
|
||||
test: {
|
||||
environment: 'jsdom',
|
||||
globals: true,
|
||||
},
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: apiProxyPath
|
||||
? {
|
||||
[apiProxyPath]: {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) =>
|
||||
path.startsWith(apiProxyPath)
|
||||
? path.slice(apiProxyPath.length) || '/'
|
||||
: path,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user