Updates the images integration to automatically mark optimizeDeps
for sharp (#3795)
* including src in npm publish * bugfix: always round dimensions before passing to sharp.resize * automatically add optimizeDeps vite config * chore: changeset
This commit is contained in:
parent
94143fcdba
commit
d143d24c72
5 changed files with 16 additions and 5 deletions
5
.changeset/neat-yaks-hope.md
Normal file
5
.changeset/neat-yaks-hope.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/image': patch
|
||||
---
|
||||
|
||||
Automatically adds the required `vite.optimizeDeps` config for `sharp`. Also ensures that only whole numbers are passed to sharp's resize transform
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
// @ts-ignore
|
||||
import loader from 'virtual:image-loader';
|
||||
import { getImage } from '../src';
|
||||
import type { ImageAttributes, ImageMetadata, TransformOptions, OutputFormat } from '../src/types';
|
||||
import { getImage } from '../src/index.js';
|
||||
import type { ImageAttributes, ImageMetadata, TransformOptions, OutputFormat } from '../src/types.js';
|
||||
|
||||
export interface LocalImageProps extends Omit<TransformOptions, 'src'>, Omit<ImageAttributes, 'src'> {
|
||||
src: ImageMetadata | Promise<{ default: ImageMetadata }>;
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
},
|
||||
"files": [
|
||||
"components",
|
||||
"dist"
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||
|
|
|
@ -75,7 +75,10 @@ const createIntegration = (options: IntegrationOptions = {}): AstroIntegration =
|
|||
function getViteConfiguration() {
|
||||
return {
|
||||
plugins: [createPlugin(_config, resolvedOptions)],
|
||||
};
|
||||
optimizeDeps: {
|
||||
include: ['image-size', 'sharp']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
@ -84,7 +84,9 @@ class SharpService implements SSRImageService {
|
|||
const sharpImage = sharp(inputBuffer, { failOnError: false });
|
||||
|
||||
if (transform.width || transform.height) {
|
||||
sharpImage.resize(transform.width, transform.height);
|
||||
const width = transform.width && Math.round(transform.width);
|
||||
const height = transform.height && Math.round(transform.height);
|
||||
sharpImage.resize(width, height);
|
||||
}
|
||||
|
||||
if (transform.format) {
|
||||
|
|
Loading…
Reference in a new issue