Skip to content

Commit 87bdfc3

Browse files
fix(build): use image-size for raster dimensions manifest
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c448a9f commit 87bdfc3

3 files changed

Lines changed: 185 additions & 45 deletions

File tree

‎config/webpack-static-image-dimensions-plugin.js‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
const fs = require('fs')
22
const path = require('path')
3-
4-
let sharp
5-
6-
try {
7-
sharp = require('sharp')
8-
} catch (error) {
9-
sharp = null
10-
}
3+
const { imageSizeFromFile } = require('image-size/fromFile')
114

125
const IMAGE_EXT_PATTERN = /\.(png|jpe?g|gif|svg|webp|avif)$/i
136

@@ -60,20 +53,16 @@ async function getImageDimensions(filePath) {
6053
return getSvgDimensionsFromContents(contents)
6154
}
6255

63-
if (!sharp) {
64-
return null
65-
}
66-
6756
try {
68-
const metadata = await sharp(filePath).metadata()
57+
const dimensions = await imageSizeFromFile(filePath)
6958

70-
if (!metadata.width || !metadata.height) {
59+
if (!dimensions.width || !dimensions.height) {
7160
return null
7261
}
7362

7463
return {
75-
width: metadata.width,
76-
height: metadata.height,
64+
width: dimensions.width,
65+
height: dimensions.height,
7766
}
7867
} catch (error) {
7968
return null

‎package-lock.json‎

Lines changed: 179 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"eslint-plugin-prettier": "^5.5.4",
4646
"eslint-webpack-plugin": "^4.2.0",
4747
"image-minimizer-webpack-plugin": "^3.8.3",
48+
"image-size": "^2.0.4",
4849
"imagemin": "^8.0.1",
4950
"imagemin-gifsicle": "^7.0.0",
5051
"imagemin-jpegtran": "^7.0.0",

0 commit comments

Comments
 (0)