You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable Turbopack loaders to conditionally apply based on file size.
Provide a simpler and clearer alternative to using RegExp with the content rule for size-based conditions.
Allow size-based conditions to work for binary files (e.g., PNG, JPG), which cannot be matched using the current content rule.
Offer functionality similar to Webpack’s url-loaderlimit option.
Non-Goals
No response
Background
Next.js 16 introduced Turbopack condition rules, which allow loaders to apply only to files matching specific criteria. There are already path and content rules, which are very useful.
It would be great to have an additional rule for file size. This would allow developers to apply a loader only to files whose size is smaller (or greater) than a provided limit. The idea is similar to Webpack’s url-loaderlimit option.
Alternative
For text-based files, this can be achieved using the existing content rule, which accepts a RegExp.
For example, to inline SVG images smaller than 4 KB, I can use the following config:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
contentrule for size-based conditions.contentrule.url-loaderlimitoption.Non-Goals
No response
Background
Next.js 16 introduced Turbopack condition rules, which allow loaders to apply only to files matching specific criteria. There are already
pathandcontentrules, which are very useful.It would be great to have an additional rule for file size. This would allow developers to apply a loader only to files whose size is smaller (or greater) than a provided limit. The idea is similar to Webpack’s
url-loaderlimit option.Alternative
For text-based files, this can be achieved using the existing
contentrule, which accepts a RegExp.For example, to inline SVG images smaller than 4 KB, I can use the following config:
While this works for textual files, it fails for binary ones (e.g.,
*.png):Also, relying on RegExp for this is not as straightforward as having a dedicated option for file size.
Proposal
Add a new condition
limitspecifying the maximum size of a file (in bytes) to apply a loader:Beta Was this translation helpful? Give feedback.
All reactions