From f3a0c3b72c3483808d5649efbcc8118927a9d0b4 Mon Sep 17 00:00:00 2001 From: Mihkel Eidast Date: Thu, 26 Jan 2023 11:46:58 +0200 Subject: [PATCH] fix: deep resolve side effects when glob does not contain / (#11807) --- packages/vite/src/node/packages.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/packages.ts b/packages/vite/src/node/packages.ts index e1fd0302290e31..d1a78a96d2ded6 100644 --- a/packages/vite/src/node/packages.ts +++ b/packages/vite/src/node/packages.ts @@ -100,7 +100,21 @@ export function loadPackageData( if (typeof sideEffects === 'boolean') { hasSideEffects = () => sideEffects } else if (Array.isArray(sideEffects)) { - hasSideEffects = createFilter(sideEffects, null, { resolve: pkgDir }) + const finalPackageSideEffects = sideEffects.map((sideEffect) => { + /* + * The array accepts simple glob patterns to the relevant files... Patterns like *.css, which do not include a /, will be treated like **\/*.css. + * https://webpack.js.org/guides/tree-shaking/ + * https://github.com/vitejs/vite/pull/11807 + */ + if (sideEffect.includes('/')) { + return sideEffect + } + return `**/${sideEffect}` + }) + + hasSideEffects = createFilter(finalPackageSideEffects, null, { + resolve: pkgDir, + }) } else { hasSideEffects = () => true }