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
The importing statements injected by Vite Plugin cause unnecessary dependencies resolving overhead.
If a plugin injects importing statements into an application, there are two flaws:
The pre-bunding discovery will skip the scanning of the content of importing statements at the startup phase.
Dependencies discovery will be triggered asynchronously.
I'm developing a huge application that needs the dependencies injection.
I'm using a Vite plugin to scan the whole project and find out injectable content, using async importing statements injecting them into a provider container(IOC).
The plugin works well but the application startup speed is horrible at the first time (or without .vite bundle cache), almost 10+ mins(vs 1 min before the migrating from Webpack), I think it is mainly caused by the second flaw.
replace the file content from const modules: any[] = await Promise.all([]) to const modules: any[] = await Promise.all([import('./pixi')]).
If without the plugin, write the replacement directly, console reports:
It's extremely fast.
Once the plugin worked, console reports:
At a large-scale application, the console reports many times for the newly founded dependencies and repeatedly reloads the page, it takes too long to start up an application without the building cache.
No matter whether it's using dynamic importing to static importing statements, the buggy case will be reproduced stably.
I tried another experiment for writing down import statements manually and enabling the plugin to rewrites the same statements, Vite handles the case very well without repeatedly re-discovery dependencies.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
Another buggy behavior is the sourcemap file resolving fail:
Sourcemap for the third party modules. e.g. Sourcemap for "/Users/zheeeng/Workspace/vvfx-new/node_modules/.pnpm/inversify@5.1.1/node_modules/inversify/lib/inversify.js" points to missing source files
Sourcemap for chunked js file under .vite. e.g. 下午10:54:23 [vite] Failed to load source map for /node_modules/.vite/chunk-WT4RPIXK.js?v=7b399ea9.
Sourcemap for cached module file under .vite. e.g. 上午10:54:23 [vite] Failed to load source map for /node_modules/.vite/@vvfx_shared_node_modules_antd_es_message.js?v=8993e4f2.
Describe the bug
The importing statements injected by Vite Plugin cause unnecessary dependencies resolving overhead.
If a plugin injects importing statements into an application, there are two flaws:
I'm developing a huge application that needs the dependencies injection.
I'm using a Vite plugin to scan the whole project and find out injectable content, using async importing statements injecting them into a provider container(IOC).
The plugin works well but the application startup speed is horrible at the first time (or without .vite bundle cache), almost 10+ mins(vs 1 min before the migrating from Webpack), I think it is mainly caused by the second flaw.
This demo plugin is as simple as
replace the file content from
const modules: any[] = await Promise.all([])
toconst modules: any[] = await Promise.all([import('./pixi')])
.If without the plugin, write the replacement directly, console reports:
It's extremely fast.
Once the plugin worked, console reports:
At a large-scale application, the console reports many times for the newly founded dependencies and repeatedly reloads the page, it takes too long to start up an application without the building cache.
No matter whether it's using dynamic importing to static importing statements, the buggy case will be reproduced stably.
I tried another experiment for writing down import statements manually and enabling the plugin to rewrites the same statements, Vite handles the case very well without repeatedly re-discovery dependencies.
There is also a minimum reproduction below.
Happy lunar new year. 🎉🎉🎉
Reproduction
https://github.com/zheeeng/vite-inject-importing-statemetns
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: