[Content Collections] Fix import.meta.env.DEV always set to true (#5700)

* fix: reset NODE_ENV on content config read

* fix: move nodeEnv setter above createServer

* chore: changeset
This commit is contained in:
Ben Holmes 2023-01-03 09:45:38 -05:00 committed by GitHub
parent bf210f7841
commit 3aa3e00a63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix `import.meta.env.DEV` always being set to `true` when using Content Collections

View file

@ -190,6 +190,7 @@ export async function loadContentConfig({
settings: AstroSettings;
}): Promise<ContentConfig | Error> {
const contentPaths = getContentPaths({ srcDir: settings.config.srcDir });
const nodeEnv = process.env.NODE_ENV;
const tempConfigServer: ViteDevServer = await createServer({
root: fileURLToPath(settings.config.root),
server: { middlewareMode: true, hmr: false },
@ -206,6 +207,9 @@ export async function loadContentConfig({
return new NotFoundError('Failed to resolve content config.');
} finally {
await tempConfigServer.close();
// Reset NODE_ENV to initial value
// Vite's `createServer()` sets NODE_ENV to 'development'!
process.env.NODE_ENV = nodeEnv;
}
const config = contentConfigParser.safeParse(unparsedConfig);
if (config.success) {