Skip to content
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

Avoid injecting unnecessary preload function if no dependencies are found in glob import #14308

Closed
4 tasks done
felixcicatt opened this issue Sep 6, 2023 · 1 comment
Closed
4 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@felixcicatt
Copy link

Description

I have a very small entry file, which does a lazy glob import. None of the files that are resolved by this glob import have dependencies.

Vite injects a function in the output, that allows preloading any dependencies. However, this code is never used. This results in the output size being doubled, so this seems wasteful.

Suggested solution

It seems this code is injected as part of the buildImportAnalysisPlugin. It would be nice if the plugin was smart enough to detect if no async imports have any dependencies. In that case, the values of the object that import.meta.glob injects would not need to be wrapped with the preload function, and the preload function itself would not need to be injected. The following example is minified, but I think it's still sufficiently readable:

In stead of:

// ... injected preload functions
p = Object.assign({
    "./components/tab-list.js": () => h(() => import("./tab-list-941ff699.js"), []),
}),

You would just get:

p = Object.assign({
    "./components/tab-list.js": () => import("./tab-list-941ff699.js"),
}),

Alternative

No response

Additional context

No response

Validations

@sapphi-red
Copy link
Member

Duplicate of #13952

@sapphi-red sapphi-red marked this as a duplicate of #13952 Sep 6, 2023
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Sep 6, 2023
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed enhancement: pending triage labels Sep 6, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants