Skip to content

Commit

Permalink
[Content Collections] Fix import.meta.env.DEV always set to true (#…
Browse files Browse the repository at this point in the history
…5700)

* fix: reset NODE_ENV on content config read

* fix: move nodeEnv setter above createServer

* chore: changeset
  • Loading branch information
bholmesdev committed Jan 3, 2023
1 parent bf210f7 commit 3aa3e00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-gifts-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix `import.meta.env.DEV` always being set to `true` when using Content Collections
4 changes: 4 additions & 0 deletions packages/astro/src/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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) {
Expand Down

0 comments on commit 3aa3e00

Please sign in to comment.