Fix image external config in build (#5073)

This commit is contained in:
Bjorn Lu 2022-10-13 23:16:08 +08:00 committed by GitHub
parent ac6e2af73c
commit 93f72f90bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/image': patch
---
Fix image external config in build

View file

@ -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: {
@ -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({