Skip to content

Commit

Permalink
fix: deep resolve side effects when glob does not contain / (#11807)
Browse files Browse the repository at this point in the history
  • Loading branch information
mihkeleidast authored Jan 26, 2023
1 parent fb77411 commit f3a0c3b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/vite/src/node/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f3a0c3b

Please sign in to comment.