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
This profiling strategy is a good way to identify unnecessary transforms caused by [barrel files](https://vitejs.dev/guide/performance.html#avoid-barrel-files).
82
-
If these logs contain files that should not be loaded when your test is run, you might have barrel files that are importing files unnecessarily.
<img alt="The module info view for an inlined module" img-light src="/ui/light-module-info.png">
118
120
<img alt="The module info view for an inlined module" img-dark src="/ui/dark-module-info.png">
119
121
120
-
## File Import
122
+
## 文件导入 {#file-import}
121
123
122
-
Some modules just take a long time to load. To identify which modules are the slowest, enable[`experimental.importDurations`](/config/experimental#experimental-importdurations)in your configuration:
Once you've identified the slow modules, there are several strategies to speed up imports:
157
+
一旦识别出慢速模块,有几种策略可以加速导入:
156
158
157
-
### Use Specific Entry Points
159
+
### 使用特定入口 {#use-specific-entry-points}
158
160
159
-
Many libraries ship multiple entry points. Importing the main entry point (which is often a [barrel file](https://vitejs.dev/guide/performance.html#avoid-barrel-files)) can pull in far more code than you need.
For example, `date-fns` re-exports hundreds of functions from its main entry point. Instead of importing from the top-level module, import directly from the specific function:
If a dependency doesn't provide granular entry points, or if third-party code imports the heavy entry point, you can use [`resolve.alias`](https://vite.dev/config/shared-options#resolve-alias) to redirect imports to a lighter alternative:
Vitest can bundle external libraries into a single file using [`deps.optimizer`](/config/deps#deps-optimizer), which reduces the overhead of importing packages with many internal modules:
This is especially effective forUI libraries and packages with deep import trees. Use `optimizer.ssr`for`node`/`edge`environments and `optimizer.client`for`jsdom`/`happy-dom`environments.
0 commit comments