fix: image size plugin

This commit is contained in:
Stephen Zhou
2026-02-25 17:25:52 +08:00
parent 7bd987c6f1
commit 3e92f85beb
3 changed files with 6 additions and 44 deletions

View File

@@ -230,8 +230,6 @@
"eslint-plugin-storybook": "10.2.6",
"husky": "9.1.7",
"iconify-import-svg": "0.1.1",
"image-size": "2.0.2",
"jiti": "1.21.7",
"jsdom": "27.3.0",
"jsdom-testing-mocks": "1.16.0",
"knip": "5.78.0",
@@ -248,7 +246,7 @@
"tsx": "4.21.0",
"typescript": "5.9.3",
"uglify-js": "3.19.3",
"vinext": "https://pkg.pr.new/hyoban/vinext@95ea343",
"vinext": "https://pkg.pr.new/hyoban/vinext@bf9b9eb",
"vite": "7.3.1",
"vite-tsconfig-paths": "6.0.4",
"vitest": "4.0.17",

16
web/pnpm-lock.yaml generated
View File

@@ -555,12 +555,6 @@ importers:
iconify-import-svg:
specifier: 0.1.1
version: 0.1.1
image-size:
specifier: 2.0.2
version: 2.0.2
jiti:
specifier: 1.21.7
version: 1.21.7
jsdom:
specifier: 27.3.0
version: 27.3.0(canvas@3.2.1)
@@ -610,8 +604,8 @@ importers:
specifier: 3.19.3
version: 3.19.3
vinext:
specifier: https://pkg.pr.new/hyoban/vinext@95ea343
version: https://pkg.pr.new/hyoban/vinext@95ea343(next@16.1.5(@babel/core@7.28.6)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(sass@1.93.2))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(typescript@5.9.3)(vite@7.3.1(@types/node@24.10.12)(jiti@1.21.7)(sass@1.93.2)(terser@5.46.0)(tsx@4.21.0)(yaml@2.8.2))(webpack@5.104.1(esbuild@0.27.2)(uglify-js@3.19.3))
specifier: https://pkg.pr.new/hyoban/vinext@bf9b9eb
version: https://pkg.pr.new/hyoban/vinext@bf9b9eb(next@16.1.5(@babel/core@7.28.6)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(sass@1.93.2))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(typescript@5.9.3)(vite@7.3.1(@types/node@24.10.12)(jiti@1.21.7)(sass@1.93.2)(terser@5.46.0)(tsx@4.21.0)(yaml@2.8.2))(webpack@5.104.1(esbuild@0.27.2)(uglify-js@3.19.3))
vite:
specifier: 7.3.1
version: 7.3.1(@types/node@24.10.12)(jiti@1.21.7)(sass@1.93.2)(terser@5.46.0)(tsx@4.21.0)(yaml@2.8.2)
@@ -7568,8 +7562,8 @@ packages:
vfile@6.0.3:
resolution: {integrity: sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==}
vinext@https://pkg.pr.new/hyoban/vinext@95ea343:
resolution: {integrity: sha512-ipoRAHuH0KBJhw7E5BlEkijmyUMH+TamZE1vbZHeG1j4Dwxt33+QbrQuE9rfFsNv7DhU/KBDqN7Mo7Wo4/CUbQ==, tarball: https://pkg.pr.new/hyoban/vinext@95ea343}
vinext@https://pkg.pr.new/hyoban/vinext@bf9b9eb:
resolution: {integrity: sha512-Nt35xoSsxpZYnW0v9zWxtbrwRkm1SClYn+QqewMhIh1dyH8ND9LHhUgDCyl02qqqiuVYX2FGVZDOWZg1KHXbUw==, tarball: https://pkg.pr.new/hyoban/vinext@bf9b9eb}
version: 0.0.5
hasBin: true
peerDependencies:
@@ -15957,7 +15951,7 @@ snapshots:
'@types/unist': 3.0.3
vfile-message: 4.0.3
vinext@https://pkg.pr.new/hyoban/vinext@95ea343(next@16.1.5(@babel/core@7.28.6)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(sass@1.93.2))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(typescript@5.9.3)(vite@7.3.1(@types/node@24.10.12)(jiti@1.21.7)(sass@1.93.2)(terser@5.46.0)(tsx@4.21.0)(yaml@2.8.2))(webpack@5.104.1(esbuild@0.27.2)(uglify-js@3.19.3)):
vinext@https://pkg.pr.new/hyoban/vinext@bf9b9eb(next@16.1.5(@babel/core@7.28.6)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(sass@1.93.2))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(typescript@5.9.3)(vite@7.3.1(@types/node@24.10.12)(jiti@1.21.7)(sass@1.93.2)(terser@5.46.0)(tsx@4.21.0)(yaml@2.8.2))(webpack@5.104.1(esbuild@0.27.2)(uglify-js@3.19.3)):
dependencies:
'@unpic/react': 1.0.2(next@16.1.5(@babel/core@7.28.6)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(sass@1.93.2))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
'@vercel/og': 0.8.6

View File

@@ -11,7 +11,6 @@ import tsconfigPaths from 'vite-tsconfig-paths'
const isCI = !!process.env.CI
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const imageDimensionCache = new Map<string, { width: number, height: number }>()
const vinextFontGoogleShimPath = fs.realpathSync(path.resolve(__dirname, 'node_modules/vinext/dist/shims/font-google.js'))
const vinextConstantsShimPath = fs.realpathSync(path.resolve(__dirname, 'node_modules/vinext/dist/shims/constants.js'))
@@ -38,34 +37,6 @@ export const Instrument_Serif = (options = {}) => googleFonts.Instrument_Serif(o
}
}
function vinextImageMetaFallback(): Plugin {
return {
name: 'vinext:image-meta-fallback',
enforce: 'pre',
async load(id) {
if (!id.startsWith('\0vinext-image-meta:'))
return null
const imagePath = id.replace('\0vinext-image-meta:', '')
const cached = imageDimensionCache.get(imagePath)
if (cached)
return `export default ${JSON.stringify(cached)};`
try {
const { imageSize } = await import('image-size')
const buffer = fs.readFileSync(imagePath)
const result = imageSize(buffer)
const dimensions = { width: result.width ?? 0, height: result.height ?? 0 }
imageDimensionCache.set(imagePath, dimensions)
return `export default ${JSON.stringify(dimensions)};`
}
catch {
return 'export default {"width":0,"height":0};'
}
},
}
}
function vinextConstantsExportPatch(): Plugin {
return {
name: 'vinext:constants-export-patch',
@@ -108,7 +79,6 @@ export default defineConfig(({ mode }) => {
mdx(),
vinextGoogleFontExportPatch(),
vinextConstantsExportPatch(),
vinextImageMetaFallback(),
vinext(),
]),
tsconfigPaths(),