Skip to content

Commit

Permalink
fix: better assetsInlineLimit runtime type checking (#10154)
Browse files Browse the repository at this point in the history
* fix: string assetsInlineLimit

* fix: better handle NaN values for `assetsInlineLimit`

* chore: prettier

* chore: simplify for requested changes

* chore: update changeset

* chore: remove tests

* chore: simplify function

* Apply suggestions from code review

---------

Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com>
  • Loading branch information
Cherry and lilnasy committed Feb 26, 2024
1 parent aa45eb9 commit e64bd07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-bears-collect.md
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fixes an issue where `config.vite.build.assetsInlineLimit` could not be set as a function.
17 changes: 8 additions & 9 deletions packages/astro/src/core/build/plugins/util.ts
Expand Up @@ -75,14 +75,13 @@ export function shouldInlineAsset(
assetPath: string,
assetsInlineLimit: NonNullable<BuildOptions['assetsInlineLimit']>
) {
if (typeof assetsInlineLimit === 'number') {
return Buffer.byteLength(assetContent) < assetsInlineLimit;
}

const result = assetsInlineLimit(assetPath, Buffer.from(assetContent));
if (result != null) {
return result;
if (typeof assetsInlineLimit === 'function') {
const result = assetsInlineLimit(assetPath, Buffer.from(assetContent));
if (result != null) {
return result;
} else {
return Buffer.byteLength(assetContent) < 4096; // Fallback to 4096kb by default (same as Vite)
}
}

return Buffer.byteLength(assetContent) < 4096; // Fallback to 4096kb by default (same as Vite)
return Buffer.byteLength(assetContent) < Number(assetsInlineLimit);
}

0 comments on commit e64bd07

Please sign in to comment.