UNPKG

@replyke/core

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

102 lines 3.47 kB
"use strict"; // Environment detection utility for cross-platform compatibility // Works with both traditional React apps and Vite-based apps Object.defineProperty(exports, "__esModule", { value: true }); exports.isDevelopment = isDevelopment; exports.isProduction = isProduction; exports.getApiBaseUrl = getApiBaseUrl; exports.getEnvVar = getEnvVar; // Helper function to safely access Vite's import.meta.env function getViteEnv() { try { // Use dynamic access to avoid TypeScript import.meta issues var globalThis_ = globalThis; if (typeof window !== 'undefined' && globalThis_.__vite_env) { return globalThis_.__vite_env; } // Try to access import.meta via eval to avoid compile-time issues if (typeof window !== 'undefined') { try { var importMeta = new Function('return typeof import !== "undefined" && import.meta')(); if (importMeta && importMeta.env) { return importMeta.env; } } catch (_a) { // Ignore errors when import.meta is not available } } return null; } catch (_b) { return null; } } /** * Safe way to check if we're in development mode * Works with both Node.js process.env and Vite import.meta.env */ function isDevelopment() { // Check if we have process.env (Node.js or bundler that provides it) if (typeof process !== 'undefined' && process.env) { return process.env.NODE_ENV === 'development'; } // Check Vite environment var viteEnv = getViteEnv(); if (viteEnv) { return viteEnv.MODE === 'development'; } // Fallback to false (assume production for safety) return false; } /** * Safe way to check if we're in production mode */ function isProduction() { // Check if we have process.env (Node.js or bundler that provides it) if (typeof process !== 'undefined' && process.env) { return process.env.NODE_ENV === 'production'; } // Check Vite environment var viteEnv = getViteEnv(); if (viteEnv) { return viteEnv.MODE === 'production'; } // Fallback to true (assume production for safety) return true; } /** * Get API base URL from environment variables * Supports both REACT_APP_ and VITE_ prefixes */ function getApiBaseUrl() { // Check process.env (traditional React apps) if (typeof process !== 'undefined' && process.env) { return process.env.REACT_APP_API_BASE_URL || 'https://api.replyke.com/api/v6'; } // Check Vite environment var viteEnv = getViteEnv(); if (viteEnv) { return viteEnv.VITE_API_BASE_URL || 'https://api.replyke.com/api/v6'; } // Fallback to default return 'https://api.replyke.com/api/v6'; } /** * Get any environment variable with fallback * Tries both VITE_ and REACT_APP_ prefixes */ function getEnvVar(name, defaultValue) { if (defaultValue === void 0) { defaultValue = ''; } // Check process.env if (typeof process !== 'undefined' && process.env) { return process.env["REACT_APP_".concat(name)] || process.env["VITE_".concat(name)] || defaultValue; } // Check Vite environment var viteEnv = getViteEnv(); if (viteEnv) { return viteEnv["VITE_".concat(name)] || viteEnv["REACT_APP_".concat(name)] || defaultValue; } return defaultValue; } //# sourceMappingURL=env.js.map