diff --git a/.changeset/happy-mayflies-sort.md b/.changeset/happy-mayflies-sort.md new file mode 100644 index 000000000..2038ea1b3 --- /dev/null +++ b/.changeset/happy-mayflies-sort.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': patch +--- + +Fix image external config in build diff --git a/packages/integrations/image/src/index.ts b/packages/integrations/image/src/index.ts index 24e70a35d..e3770d5e9 100644 --- a/packages/integrations/image/src/index.ts +++ b/packages/integrations/image/src/index.ts @@ -52,7 +52,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte // During SSG builds, this is used to track all transformed images required. const staticImages = new Map>(); - function getViteConfiguration() { + function getViteConfiguration(isDev: boolean) { return { plugins: [createPlugin(_config, resolvedOptions)], build: { @@ -62,8 +62,9 @@ export default function integration(options: IntegrationOptions = {}): AstroInte }, ssr: { noExternal: ['@astrojs/image', resolvedOptions.serviceEntryPoint], - // CJS dependencies used by `serviceEntryPoint` - external: ['http-cache-semantics', 'image-size', 'mime'], + // Externalize CJS dependencies used by `serviceEntryPoint`. Vite dev mode has trouble + // loading these modules with `ssrLoadModule`, but works in build. + external: isDev ? ['http-cache-semantics', 'image-size', 'mime'] : [], }, assetsInclude: ['**/*.wasm'], }; @@ -75,7 +76,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte 'astro:config:setup': async ({ command, config, updateConfig, injectRoute }) => { needsBuildConfig = !config.build?.server; _config = config; - updateConfig({ vite: getViteConfiguration() }); + updateConfig({ vite: getViteConfiguration(command === 'dev') }); if (command === 'dev' || config.output === 'server') { injectRoute({