diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index 740cca24b6a661..590142a13ce276 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -223,7 +223,7 @@ function esbuildScanPlugin( filter: /^[\w@][^:]/ }, async ({ path: id, importer }) => { - if (exclude?.includes(id)) { + if (exclude?.some((e) => e === id || id.startsWith(e + '/'))) { return externalUnlessEntry({ path: id }) } if (depImports[id]) {