refactor: make loadEnv async
This commit is contained in:
parent
02c525ecc0
commit
e43c2f56da
4 changed files with 5 additions and 7 deletions
2
packages/astro/config.d.ts
vendored
2
packages/astro/config.d.ts
vendored
|
@ -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>>;
|
||||
|
|
|
@ -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(), '');
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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`
|
||||
|
|
Loading…
Add table
Reference in a new issue