Skip to content

Commit

Permalink
Fix image external config in build (#5073)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 13, 2022
1 parent ac6e2af commit 93f72f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-mayflies-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/image': patch
---

Fix image external config in build
9 changes: 5 additions & 4 deletions packages/integrations/image/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Map<string, TransformOptions>>();

function getViteConfiguration() {
function getViteConfiguration(isDev: boolean) {
return {
plugins: [createPlugin(_config, resolvedOptions)],
build: {
Expand All @@ -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'],
};
Expand All @@ -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({
Expand Down

0 comments on commit 93f72f9

Please sign in to comment.