diff options
author | 2022-11-08 11:14:51 -0500 | |
---|---|---|
committer | 2022-11-08 11:14:51 -0500 | |
commit | d701ae074a4a5c7a5891e31ca50d7c51f56b353c (patch) | |
tree | 3a4eff0b15b733f63a11f51673a6d64943627318 /packages/integrations/image/src/vite-plugin-astro-image.ts | |
parent | a79a37cad549b21f91599ff86899e456d9dcc7df (diff) | |
download | astro-d701ae074a4a5c7a5891e31ca50d7c51f56b353c.tar.gz astro-d701ae074a4a5c7a5891e31ca50d7c51f56b353c.tar.zst astro-d701ae074a4a5c7a5891e31ca50d7c51f56b353c.zip |
Allow image-pool to be used as its own Worker (#5317)
* Allow image-pool to be used as its own Worker
* Adding a changeset
* fix image tests
* update picture tests
* Pass the current URL
Diffstat (limited to 'packages/integrations/image/src/vite-plugin-astro-image.ts')
-rw-r--r-- | packages/integrations/image/src/vite-plugin-astro-image.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/integrations/image/src/vite-plugin-astro-image.ts b/packages/integrations/image/src/vite-plugin-astro-image.ts index 04f230341..ee06b0d5c 100644 --- a/packages/integrations/image/src/vite-plugin-astro-image.ts +++ b/packages/integrations/image/src/vite-plugin-astro-image.ts @@ -113,6 +113,27 @@ export function createPlugin(config: AstroConfig, options: Required<IntegrationO return next(); }); }, + outputOptions(outputOptions) { + if(resolvedConfig.build.ssr) { + // Build the image-pool chunk to the top-level and not inside of a chunks/ + // folder. This is because the wasm is built at the top-level and this makes + // it accessible from the pool worker. + const chunkFileNames = outputOptions.chunkFileNames; + outputOptions.chunkFileNames = (chunk) => { + for(const name of Object.keys(chunk.modules)) { + if(name.endsWith('vendor/squoosh/image-pool.js')) { + return '[name].[hash].mjs'; + } + } + + if(typeof chunkFileNames === 'function') { + return chunkFileNames.call(this, chunk); + } + + return chunkFileNames!; + }; + } + }, async renderChunk(code) { const assetUrlRE = /__ASTRO_IMAGE_ASSET__([a-z\d]{8})__(?:_(.*?)__)?/g; |