UNPKG

rasengan

Version:

The modern React Framework

81 lines (80 loc) 2.95 kB
/** * Function to define the config for the app * It will be used by vite.config.ts and other files in other to configure the app * @param {AppConfig | AppConfigFunction | AppConfigFunctionAsync} loadedConfig */ export const defineConfig = async (loadedConfig) => { return async () => { let config; // Check if the loadedConfig is a function if (typeof loadedConfig === 'function') { // Call the function to get the config const result = loadedConfig(); // Check if it's a promise (asynchronous function) if (result instanceof Promise) { config = await result; // Await the promise result (AppConfigFunctionAsync) } else { config = result; // Synchronous function result (AppConfigFunction) } } else { config = loadedConfig; } const { ssr, server, vite, redirects } = config; // Define default values for vite config coming from loadedConfig.vite const defaultViteConfig = { ...vite, resolve: { symbole: vite?.resolve?.symbole || '@', alias: vite?.resolve?.alias || [], }, }; // Define default values for server config coming from loadedConfig.server const defaultServerConfig = { development: { port: server?.development?.port || undefined, open: server?.development?.open || false, }, }; // Define default values for redirects config coming from loadedConfig.redirects const defaultRedirectsConfig = redirects || (() => new Promise((resolve) => resolve([]))); try { const config = { ssr: ssr ?? true, server: defaultServerConfig, vite: { ...defaultViteConfig, resolve: { alias: [ { find: defaultViteConfig.resolve.symbole, replacement: './src', }, ...defaultViteConfig.resolve.alias, ], }, }, redirects: defaultRedirectsConfig, }; return config; } catch (error) { return { ssr: true, vite: { appType: 'custom', resolve: { alias: [ { find: '@', replacement: './src', }, ], }, }, redirects: () => new Promise((resolve) => resolve([])), }; } }; };