You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

100 lines
3.1 KiB

import { defineConfig, mergeConfig } from "vite";
import { createBuildConfig } from "./vite.config.common.mts";
import { loadAppConfig } from "./vite.config.utils.mts";
export default defineConfig(async ({ mode }) => {
console.log(`[VITE WEB CONFIG] Web config called with mode: ${mode}`);
console.log(`[VITE WEB CONFIG] NODE_ENV: ${process.env.NODE_ENV}`);
const baseConfig = await createBuildConfig('web');
console.log(`[VITE WEB CONFIG] Base config loaded, plugins count: ${baseConfig.plugins?.length || 0}`);
const appConfig = await loadAppConfig();
// Environment-specific configuration based on mode
const getEnvironmentConfig = (mode: string) => {
switch (mode) {
case 'production':
return {
// Production optimizations
build: {
minify: 'terser',
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
vendor: ['vue', 'vue-router', 'pinia'],
utils: ['luxon', 'ramda', 'zod'],
crypto: ['@ethersproject/wallet', '@ethersproject/hdnode', 'ethereum-cryptography'],
sql: ['@jlongster/sql.js', 'absurd-sql']
}
}
}
},
define: {
__DEV__: false,
__TEST__: false,
__PROD__: true
}
};
case 'test':
return {
// Test environment configuration
build: {
minify: false,
sourcemap: true,
rollupOptions: {
output: {
manualChunks: undefined
}
}
},
define: {
__DEV__: false,
__TEST__: true,
__PROD__: false
}
};
default: // development
return {
// Development configuration
build: {
minify: false,
sourcemap: true,
rollupOptions: {
output: {
manualChunks: undefined
}
}
},
define: {
__DEV__: true,
__TEST__: false,
__PROD__: false
}
};
}
};
const environmentConfig = getEnvironmentConfig(mode);
console.log(`[VITE WEB CONFIG] Environment config for mode ${mode}:`, Object.keys(environmentConfig));
const finalConfig = mergeConfig(baseConfig, {
...environmentConfig,
// Ensure source maps are enabled for development and test modes
// This affects both dev server and build output
sourcemap: mode === 'development' || mode === 'test',
// Server configuration inherited from base config
// CORS headers removed to allow images from any domain
plugins: []
});
console.log(`[VITE WEB CONFIG] Final web config plugins:`, finalConfig.plugins?.map(p => typeof p === 'object' && p && 'name' in p ? p.name : 'unnamed').filter(Boolean));
console.log(`[VITE WEB CONFIG] Final web config build settings:`, {
minify: finalConfig.build?.minify,
sourcemap: finalConfig.sourcemap,
mode: finalConfig.mode
});
return finalConfig;
});