-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Conversation
✅ Deploy Preview for vite-docs-main ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
7ce904b
to
ef5a0a3
Compare
assetsInlineLimit
. assetsInlineLimit
.
assetsInlineLimit
. assetsInlineLimit
.
721b0d1
to
8b50a0b
Compare
…tring`, `contentSize: number` and currently accrued bundled size `totalBundledSize: number`
8b50a0b
to
17ebf9a
Compare
assetsInlineLimit
. build.assetsInlineLimit
Yeah, great feature. Any infos about when this will be available? |
Could I get an update on where this currently stands? We have little to zero control over assets bundling now and it's starting to cause issues. Edit: Also, what's the consensus on #2909 - should SVG be under the inline assets umbrella without base64? |
This is still in the project board for team discussion, which you can find at https://github.com/orgs/vitejs/projects/1/views/9. We haven't got around discussing it yet recently. |
url = fileToInlinedAsset(file, content) | ||
size = 0 | ||
} else if (file.endsWith('.svg') === false) { | ||
const inlinedURL = fileToInlinedAsset(file, content) |
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;
{
name: string
bufferSize: number
size(): number
totalSize(): number
}
And it isn't additional code/complexity either, which is nice.
Though I would want filePath
in addition to name
. 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 not totalSize
.
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 the current size given to you is a lie
- Getting the real size from said number
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 👍🏼
Any news on this PR? what stops it from being merged? |
For people following this PR, I've made a simpler scoped update in #15366 |
Description
assetsInlineLimit
can now accept a callback for opting into inlining on a case by case basis.filePath: string
,contentSize: number
and currently accrued bundled sizetotalBundledSize: number
.base64
size as opposed to file-size for size.4kb
to6kb
so current inlined builds won't change.playground/css/vite.config-relative-base.js
to use the callback.Additional context
Testing!
I had a difficult time testing this locally, not sure how to link to my local fork using Yarn Berry (
v3
)No matter
file
,link
orportal
prefixes used inpackage.json
it couldn't find the vite executable.Maybe someone could help out with that, so it'll be easier to try it out locally.
What I did instead was create a patch in yarn to test it out, but that's modifying the distributed javascript bundles.
Should close the PR if there is already a non intrusive way to inline on a case by case basis for, e.g
FontFace woff2
files.But I would love help on how to run vite locally referenced using Yarn/Berry for future reference if that's possible.
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).