Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-emitfile-serve-warning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes the `emitFile() is not supported in serve mode` warning that appears during `astro dev` when using integrations that inject before-hydration scripts (e.g. `@astrojs/react`)
7 changes: 6 additions & 1 deletion packages/astro/src/vite-plugin-scripts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin as VitePlugin } from 'vite';
import type { Plugin as VitePlugin, ConfigEnv } from 'vite';
import type { AstroSettings } from '../types/astro.js';
import type { InjectedScriptStage } from '../types/public/integrations.js';
import { ASTRO_VITE_ENVIRONMENT_NAMES } from '../core/constants.js';
Expand All @@ -14,8 +14,12 @@ export const PAGE_SCRIPT_ID = `${SCRIPT_ID_PREFIX}${'page' as InjectedScriptStag
export const PAGE_SSR_SCRIPT_ID = `${SCRIPT_ID_PREFIX}${'page-ssr' as InjectedScriptStage}.js`;

export default function astroScriptsPlugin({ settings }: { settings: AstroSettings }): VitePlugin {
let command: 'build' | 'serve';
return {
name: 'astro:scripts',
config(_: any, env: ConfigEnv) {
command = env.command;
},

resolveId: {
filter: {
Expand Down Expand Up @@ -58,6 +62,7 @@ export default function astroScriptsPlugin({ settings }: { settings: AstroSettin
},
},
buildStart() {
if (command === 'serve') return;
const hasHydrationScripts = settings.scripts.some((s) => s.stage === 'before-hydration');
if (
hasHydrationScripts &&
Expand Down
Loading