refactor: make loadEnv async

This commit is contained in:
Nate Moore 2022-06-27 14:42:14 -04:00
parent 02c525ecc0
commit e43c2f56da
4 changed files with 5 additions and 7 deletions

View file

@ -9,4 +9,4 @@ export function defineConfig(config: AstroUserConfig): AstroUserConfig;
/**
* Synchronously load environment variables from default location
*/
export function loadEnv(): Record<string, any>;
export function loadEnv(): Promise<Record<string, any>>;

View file

@ -1,6 +1,5 @@
import { loadEnv as loadViteEnv } from 'vite';
export function loadEnv() {
export async function loadEnv() {
const { loadEnv: loadViteEnv } = await import('vite');
const { MODE } = process.env;
const PROD = MODE === 'production';
const env = loadViteEnv(MODE, process.cwd(), '');

View file

@ -1,6 +1,6 @@
import { defineConfig, loadEnv } from 'astro/config';
const { MODE } = loadEnv();
const { MODE } = await loadEnv();
export default defineConfig({
site: `https://${MODE}.my-site.com`

View file

@ -1,7 +1,6 @@
import { defineConfig, loadEnv } from 'astro/config';
const { MODE, PROD, DEV } = loadEnv();
console.log({ MODE, PROD, DEV })
const { MODE } = await loadEnv();
export default defineConfig({
site: `https://${MODE}.my-site.com`