Fix image external config in build (#5073)
This commit is contained in:
parent
ac6e2af73c
commit
93f72f90bc
2 changed files with 10 additions and 4 deletions
5
.changeset/happy-mayflies-sort.md
Normal file
5
.changeset/happy-mayflies-sort.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/image': patch
|
||||
---
|
||||
|
||||
Fix image external config in build
|
|
@ -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({
|
||||
|
|
Loading…
Reference in a new issue