-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support callback for build.assetsInlineLimit
#8717
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is running
filetoInlinedAsset
on every asset file even if it doesn't end up get inlined, seems wasteful especially when there are many larger files that don't need to be inlined.I think we should just use the raw buffer size like before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyx990803 Fair enough, but being accurate with size is inherently important as many small add up.
However I got the same feedback internally and the current design is to just pass an object with various methods
So instead of passing three arguments, it's one argument with "heavy" stuff as computed on demand;
And it isn't additional code/complexity either, which is nice.
Though I would want
filePath
in addition toname
. Sometimes you're just looking for that one file, and other times it's all the files in a path.Let the user decide if it's wasteful or not, at least Vite won't be doing it now unless opt-in, and even then you can choose to do it for e.g just
assets/*
Will that work for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the object is a good idea, but I don't think we should expose
size()
here. It is a clever trick but we will be allowing users to easily reach for inefficient code. For most use cases, it is ok to use the file size and we should promote that.I think we should have the object but with a plain
size
prop and nottotalSize
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@patak-dev The problem is bufferSize doesn't match the REAL size and that is the concern this PR is trying to solve.
We have a bunch of assets, some should be inlined and some should not.
File name matters (explicit inlining)
Paths matter (glob inlining)
Size matters (It's too big, opt out for this one)
TotalSize (We're reaching our limit, stop inlining)
Now, all of these could inherently be done by the user in the callback, but it would cumbersome.
for instance, totalSize is very easy to do outside, just
totalSize += realSize
outside the callback.But expecting the user to know and do
That being said, I've already written this for myself, so it's not a big deal.
Yeah I agree having an object there makes more sense for any further information needed to be passed down.
At the very least, using a fixed static size as a boolean to decide is broken so that would be fixed regardless of what data is sent.
Your call
👍🏼
That being said, I need help with a few things:
What's the consensus on #2909 - should SVG be under the inline assets umbrella without base64?
I might need some help resolving the conflict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you say, if someone needs the
totalSize
, it can be computed externally. I don't think it is common enough to justify having it in core.And the same goes for the real size, we can be more clear in the docs and add a rationale about why the API is using the file size.
About #2909, I think it should but that PR should be merged first, no? We can already move with this PR before that IIUC.
Let me know if you try to resolve the conflict and you get blocked and I'll check it out 👍🏼