UNPKG

@ou-imdt/utils

Version:

Utility library for interactive media development

31 lines (30 loc) 929 B
import getEnvVariable from './getEnvVariable.js'; /** * Utility function to check if the current environment is development. * It checks both Vite's built-in DEV variable and Node.js's NODE_ENV variable. * * @returns {boolean} - True if the environment is development, false otherwise. * * @example * * Assuming NODE_ENV or --mode set to 'development' * if (isDevelopment()) { * console.log('Running in development mode'); * } else { * console.log('Not running in development mode'); * } * * @example * Using in npm scripts in package.json * { * "scripts": { * "dev": "vite --mode development", //vite * "start:dev": "NODE_ENV=development node server.js" //node * } * } */ export default function isDevelopment() { const viteDev = typeof import.meta !== 'undefined' && import.meta.env.DEV; const nodeEnv = getEnvVariable('NODE_ENV') === 'development'; return viteDev || nodeEnv; }