From 12b075129564796389799aa60e4a4e9ea2c96958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0?= Date: Thu, 29 May 2025 13:56:30 +0900 Subject: [PATCH 1/3] feat: stabilize `optimizeDeps.noDiscovery` (#19984) --- config/dep-optimization-options.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/dep-optimization-options.md b/config/dep-optimization-options.md index 70d338ad..1813b546 100644 --- a/config/dep-optimization-options.md +++ b/config/dep-optimization-options.md @@ -78,6 +78,13 @@ Certain options are omitted since changing them would not be compatible with Vit Set to `true` to force dependency pre-bundling, ignoring previously cached optimized dependencies. +## optimizeDeps.noDiscovery + +- **Type:** `boolean` +- **Default:** `false` + +When set to `true`, automatic dependency discovery will be disabled and only dependencies listed in `optimizeDeps.include` will be optimized. CJS-only dependencies must be present in `optimizeDeps.include` during dev. + ## optimizeDeps.holdUntilCrawlEnd - **Experimental:** [Give Feedback](https://github.com/vitejs/vite/discussions/15834) From 76e90fdf826839457a948b34079f1cbd9f967fba Mon Sep 17 00:00:00 2001 From: James Opstad <13586373+jamesopstad@users.noreply.github.com> Date: Thu, 29 May 2025 09:39:59 +0100 Subject: [PATCH 2/3] fix: treat all `optimizeDeps.entries` values as globs (#20045) --- config/dep-optimization-options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/dep-optimization-options.md b/config/dep-optimization-options.md index 1813b546..8008b331 100644 --- a/config/dep-optimization-options.md +++ b/config/dep-optimization-options.md @@ -10,7 +10,7 @@ Unless noted, the options in this section are only applied to the dependency opt By default, Vite will crawl all your `.html` files to detect dependencies that need to be pre-bundled (ignoring `node_modules`, `build.outDir`, `__tests__` and `coverage`). If `build.rollupOptions.input` is specified, Vite will crawl those entry points instead. -If neither of these fit your needs, you can specify custom entries using this option - the value should be a [`tinyglobby` pattern](https://github.com/SuperchupuDev/tinyglobby) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. Only `node_modules` and `build.outDir` folders will be ignored by default when `optimizeDeps.entries` is explicitly defined. If other folders need to be ignored, you can use an ignore pattern as part of the entries list, marked with an initial `!`. If you don't want to ignore `node_modules` and `build.outDir`, you can specify using literal string paths (without `tinyglobby` patterns) instead. +If neither of these fit your needs, you can specify custom entries using this option - the value should be a [`tinyglobby` pattern](https://github.com/SuperchupuDev/tinyglobby) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. Only `node_modules` and `build.outDir` folders will be ignored by default when `optimizeDeps.entries` is explicitly defined. If other folders need to be ignored, you can use an ignore pattern as part of the entries list, marked with an initial `!`. `node_modules` will not be ignored for patterns that explicitly include the string `node_modules`. ## optimizeDeps.exclude From 663cd7ec4eef43a592631258a515adb0f6b30b18 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Fri, 30 May 2025 10:07:29 +0800 Subject: [PATCH 3/3] fix: resolved conflict --- config/dep-optimization-options.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/config/dep-optimization-options.md b/config/dep-optimization-options.md index bcb17933..ae19813b 100644 --- a/config/dep-optimization-options.md +++ b/config/dep-optimization-options.md @@ -10,11 +10,7 @@ 默认情况下,Vite 会抓取你的 `index.html` 来检测需要预构建的依赖项(忽略了`node_modules`、`build.outDir`、`__tests__` 和 `coverage`)。如果指定了 `build.rollupOptions.input`,Vite 将转而去抓取这些入口点。 -<<<<<<< HEAD -如果这两者都不合你意,则可以使用此选项指定自定义条目——该值需要遵循 [tinyglobby 模式](https://github.com/SuperchupuDev/tinyglobby) ,或者是相对于 Vite 项目根目录的匹配模式数组。当显式声明了 `optimizeDeps.entries` 时默认只有 `node_modules` 和 `build.outDir` 文件夹会被忽略。如果还需忽略其他文件夹,你可以在模式列表中使用以 `!` 为前缀的、用来匹配忽略项的模式。如果你不想忽略 `node_modules` 和 `build.outDir`,你可以选择直接使用字符串路径(不使用 tinyglobby 模式)。 -======= -If neither of these fit your needs, you can specify custom entries using this option - the value should be a [`tinyglobby` pattern](https://github.com/SuperchupuDev/tinyglobby) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. Only `node_modules` and `build.outDir` folders will be ignored by default when `optimizeDeps.entries` is explicitly defined. If other folders need to be ignored, you can use an ignore pattern as part of the entries list, marked with an initial `!`. `node_modules` will not be ignored for patterns that explicitly include the string `node_modules`. ->>>>>>> 76e90fdf826839457a948b34079f1cbd9f967fba +如果这两者都不合你意,则可以使用此选项指定自定义条目——该值需要遵循 [tinyglobby 模式](https://github.com/SuperchupuDev/tinyglobby) ,或者是相对于 Vite 项目根目录的匹配模式数组。当显式声明了 `optimizeDeps.entries` 时默认只有 `node_modules` 和 `build.outDir` 文件夹会被忽略。如果还需忽略其他文件夹,你可以在模式列表中使用以 `!` 为前缀的、用来匹配忽略项的模式。对于明确包含字符串 `node_modules` 的模式,不会忽略 `node_modules`。 ## optimizeDeps.exclude {#optimizedeps-exclude} @@ -82,12 +78,12 @@ export default defineConfig({ 设置为 `true` 可以强制依赖预构建,而忽略之前已经缓存过的、已经优化过的依赖。 -## optimizeDeps.noDiscovery +## optimizeDeps.noDiscovery {#optimizedeps-no-discovery} -- **Type:** `boolean` -- **Default:** `false` +- **类型:** `boolean` +- **默认:** `false` -When set to `true`, automatic dependency discovery will be disabled and only dependencies listed in `optimizeDeps.include` will be optimized. CJS-only dependencies must be present in `optimizeDeps.include` during dev. +设置为 true 时,自动依赖项发现将被禁用,并且仅优化 `optimizeDeps.include` 中列出的依赖项。在开发过程中,仅 CJS 依赖项必须存在于 `optimizeDeps.include` 中。 ## optimizeDeps.holdUntilCrawlEnd