Closed btea closed 3 days ago
I think we should optimize Object.keys(import.meta.glob
/ Object.values(import.meta.glob
instead of introducing a new query so that users won't need to think about it.
It would be great if rollup or a minifier can optimize this case, but I guess it's easier to do it on our side.
Thanks for your suggestion. But maybe we just need to optimize Object.keys(import.meta.glob
, and Object.values(import.meta.glob
should follow the original logic.
Thanks for the review, the code has been updated.
As far as I understand, Object.values(import.meta.glob(''))
can only follow the normal parsing process to get the corresponding object and then get the corresponding values. Are there any other optimization methods here?
I was thinking that the keys could be minimized, like "0"
or "1"
instead of paths like "./src/foo.png"
.
I was also thinking there could be a further optimization in the future where we replace the Object.keys()
or Object.values()
altogether and directly replace them as an array, but that's harder and we can leave that for later. So if the PR is more of a stop-gap optimization for Object.keys()
, maybe we can also do a stop-gap for Object.values()
.
@bluwy Thanks for the detailed instructions. 👍
It'd be nice to replace Object.values(import.meta.glob(''))
with Object.values([() => import('')])
. I'm open with having that. That said, if the minifier implements the more advanced minification of Object.values({ 'a': 'b' })
-> ['b']
, we don't need that optimization. I'm fine with merging this PR without that change for that reason.
On the other hand, replacing Object.keys({ a: () => import('') })
with Object.keys({ a: '' })
has a benefit to do it on the Vite side. This will remove the unused import()
and skips that file from being bundled by rollup. We cannot achieve that by improving a minifier because we run it after the chunks are generated.
Thank you for your guidance. I have processed Object.values(import.meta.glob(''))
according to @sapphi-red suggestion.
Yeah I think it's worth implementing the Object.values
optimization for now since it doesn't seem like any minifier implements it yet. Thanks for updating with it @btea
Description
close #18662