From 8eff2a33dddded8d71062c03cc17796a19277658 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 1 Aug 2023 20:50:55 +0800 Subject: [PATCH 1/2] perf: replace startsWith with === --- packages/vite/src/node/plugins/importAnalysisBuild.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index a5b961a3bb3718..de9bfada52b7dc 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -183,7 +183,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { ? // If `experimental.renderBuiltUrl` or `build.modulePreload.resolveDependencies` are used // the dependencies are already resolved. To avoid the need for `new URL(dep, import.meta.url)` // a helper `__vitePreloadRelativeDep` is used to resolve from relative paths which can be minimized. - `function(dep, importerUrl) { return dep.startsWith('.') ? new URL(dep, importerUrl).href : dep }` + `function(dep, importerUrl) { return return dep[0] === '.' ? new URL(dep, importerUrl).href : dep }` : optimizeModulePreloadRelativePaths ? // If there isn't custom resolvers affecting the deps list, deps in the list are relative // to the current chunk and are resolved to absolute URL by the __vitePreload helper itself. From 472f5da2288221b276eb57c4272d5ebe984df84c Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 1 Aug 2023 21:03:27 +0800 Subject: [PATCH 2/2] Update packages/vite/src/node/plugins/importAnalysisBuild.ts Co-authored-by: patak --- packages/vite/src/node/plugins/importAnalysisBuild.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index de9bfada52b7dc..1d046eb49f581e 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -183,7 +183,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { ? // If `experimental.renderBuiltUrl` or `build.modulePreload.resolveDependencies` are used // the dependencies are already resolved. To avoid the need for `new URL(dep, import.meta.url)` // a helper `__vitePreloadRelativeDep` is used to resolve from relative paths which can be minimized. - `function(dep, importerUrl) { return return dep[0] === '.' ? new URL(dep, importerUrl).href : dep }` + `function(dep, importerUrl) { return dep[0] === '.' ? new URL(dep, importerUrl).href : dep }` : optimizeModulePreloadRelativePaths ? // If there isn't custom resolvers affecting the deps list, deps in the list are relative // to the current chunk and are resolved to absolute URL by the __vitePreload helper itself.