The pre-bundling step will only need to be re-run when one of the above has changed. package-lock.json, yarn.lock, pnpm-lock.yaml or bun.lockb. Package manager lockfile content, e.g.It determines whether it needs to re-run the pre-bundling step based on a few sources: Vite caches the pre-bundled dependencies in node_modules/.vite. For example, adding an esbuild plugin to handle special files in dependencies. You can further customize esbuild too with the optimizeDeps.esbuildOptions option. If the dependency is large (with many internal modules) or is CommonJS, then you should include it If the dependency is small and is already valid ESM, you can exclude it and let the browser load it directly. This will cause the server to immediately re-bundle after server start.īoth include and exclude can be used to deal with this. This means Vite won't be able to discover the import on the initial scan - it can only discover it after the file is requested by the browser and transformed. For example, maybe the import is created as a result of a plugin transform. In cases where you want to explicitly include/exclude dependencies from the list, use the optimizeDeps config options.Ī typical use case for optimizeDeps.include or optimizeDeps.exclude is when you have an import that is not directly discoverable in the source code. The default dependency discovery heuristics may not always be desirable. If you stumble on this issue, use npm pack on the linked dependency to fix it. If not, you can add the dependency to optimizeDeps.include and in your config.ĭue to differences in linked dependency resolution, transitive dependencies can deduplicate incorrectly, causing issues when used in runtime. However, this requires the linked dep to be exported as ESM. It will not attempt to bundle the linked dep, and will analyze the linked dep's dependency list instead. Vite automatically detects dependencies that are not resolved from node_modules and treats the linked dep as source code. In a monorepo setup, a dependency may be a linked package from the same repo. The pre-bundling is performed with esbuild so it's typically very fast.Īfter the server has already started, if a new dependency import is encountered that isn't already in the cache, Vite will re-run the dep bundling process and reload the page if needed. "bare imports" that expect to be resolved from node_modules) and use these found imports as entry points for the pre-bundle. If an existing cache is not found, Vite will crawl your source code and automatically discover dependency imports (i.e. Dependency pre-bundling only applies in development mode, and uses esbuild to convert dependencies to ESM.
0 Comments
Leave a Reply. |