UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

42 lines (39 loc) 983 B
import fs__default from 'fs'; /* eslint-disable @typescript-eslint/no-require-imports */ /** * 用 dotenv-expand 加载环境变量 * @param file 文件路径,默认 .env.local * @param param 参数 * * @example * ```ts * loadEnv(); * * loadEnv('.env'); * * loadEnv('.env.local', { * debug: false, // 是否打印日志,默认 true * }); * ``` */ function loadDotenv(file, options) { var _a; if (file === void 0) { file = '.env.local'; } var dotenv = require('dotenv'); var dotenvExpand = require('dotenv-expand'); if (!fs__default.existsSync(file)) { console.log(">>> loadEnv ".concat(file, " \u4E0D\u5B58\u5728")); return; } var myEnv = dotenv.config({ path: file }); dotenvExpand.expand(myEnv); var debug = (_a = options === null || options === void 0 ? void 0 : options.debug) !== null && _a !== void 0 ? _a : true; if (debug) { console.log(">>> loadEnv ".concat(file, " success")); } } export { loadDotenv };