Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
adds hacky workaround fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderniebuhr committed Jan 4, 2024
1 parent d30a95e commit 8d8ed84
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 56 deletions.
14 changes: 13 additions & 1 deletion .changeset/curvy-falcons-count.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@
'@astrojs/cloudflare': minor
---

TBA
Adds the option to only run image optimization on images during build-time. :warning: This mode does not work with on-demand (SSR) image optimization.

```diff
import {defineConfig} from "astro/config";
import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
output: 'server'
adapter: cloudflare({
+ imageService: 'compile'
}),
})
```
42 changes: 40 additions & 2 deletions packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,26 @@ export default function createIntegration(args?: Options): AstroIntegration {
'ignored-bare-import': 'silent',
},
plugins: !args?.wasmModuleImports
? []
? [
{
name: 'sharp',
setup(build) {
if (!args?.imageService || args?.imageService === 'compile') {
build.onResolve({ filter: /^sharp/ }, (args) => ({
path: args.path,
namespace: 'sharp-ns',
}));

build.onLoad({ filter: /.*/, namespace: 'sharp-ns' }, (a) => {
return {
contents: JSON.stringify(''),
loader: 'json',
};
});
}
},
},
]
: [rewriteWasmImportPath({ relativePathToAssets })],
});
}
Expand Down Expand Up @@ -347,7 +366,26 @@ export default function createIntegration(args?: Options): AstroIntegration {
'ignored-bare-import': 'silent',
},
plugins: !args?.wasmModuleImports
? []
? [
{
name: 'sharp',
setup(build) {
if (!args?.imageService || args?.imageService === 'compile') {
build.onResolve({ filter: /^sharp/ }, (args) => ({
path: args.path,
namespace: 'sharp-ns',
}));

build.onLoad({ filter: /.*/, namespace: 'sharp-ns' }, (a) => {
return {
contents: JSON.stringify(''),
loader: 'json',
};
});
}
},
},
]
: [
rewriteWasmImportPath({
relativePathToAssets: isModeDirectory
Expand Down
15 changes: 0 additions & 15 deletions packages/cloudflare/test/assets-compile-time.test.js

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions packages/cloudflare/test/fixtures/assets-compile-time/package.json

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

0 comments on commit 8d8ed84

Please sign in to comment.