[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:
parent
bf210f7841
commit
3aa3e00a63
2 changed files with 9 additions and 0 deletions
5
.changeset/yellow-gifts-complain.md
Normal file
5
.changeset/yellow-gifts-complain.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix `import.meta.env.DEV` always being set to `true` when using Content Collections
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue