Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix image external config in build #5073

Merged
merged 1 commit into from
Oct 13, 2022
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/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