summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar James Ross <james@jross.me> 2024-02-26 14:42:42 +0000
committerGravatar GitHub <noreply@github.com> 2024-02-26 20:12:42 +0530
commite64bd0740b44aed5cfaf67e5c37a1c56ed4442f4 (patch)
treed231404d72f796342a0ec21dbccc5d2727d616e1
parentaa45eb9fa60b254e859750d9cef671daa605b213 (diff)
downloadastro-e64bd0740b44aed5cfaf67e5c37a1c56ed4442f4.tar.gz
astro-e64bd0740b44aed5cfaf67e5c37a1c56ed4442f4.tar.zst
astro-e64bd0740b44aed5cfaf67e5c37a1c56ed4442f4.zip
fix: better assetsInlineLimit runtime type checking (#10154)
* 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>
-rw-r--r--.changeset/late-bears-collect.md5
-rw-r--r--packages/astro/src/core/build/plugins/util.ts17
2 files changed, 13 insertions, 9 deletions
diff --git a/.changeset/late-bears-collect.md b/.changeset/late-bears-collect.md
new file mode 100644
index 000000000..f2bcd193f
--- /dev/null
+++ b/.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.
diff --git a/packages/astro/src/core/build/plugins/util.ts b/packages/astro/src/core/build/plugins/util.ts
index 7297a1f6f..07b18a887 100644
--- a/packages/astro/src/core/build/plugins/util.ts
+++ b/packages/astro/src/core/build/plugins/util.ts
@@ -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);
}