vitejs-investigation

[EDIT] Solution

Note

Problem can be fixed using resolve.dedupe see vitejs/vite/issues/15829

solution

{
  "resolve": {
    "dedupe": ["picocolors"]
  }
}

"hoistingLimits": "dependencies" breaks the vite deps hashing

"hoistingLimits" change the way vite compute dynamic dependency hash.

  • "hoistingLimits": "none" : 1 chunk for picocolors
  • "hoistingLimits": "dependencies" : 2 chunk for picocolors

Results

hoistingLimits Chunks
"none" picocolors.browser-v4etCjPf.js
"dependencies" picocolors.browser-9Ml1HsQB.js
picocolors.browser-qHnddVYe.js

✅ with "hoistingLimits": "none"

{
  "installConfig": {
    "hoistingLimits": "none"
  }
}

yarn && yarn run build

vite v5.0.12 building for production...
✓ 10 modules transformed.
dist/index.html                             0.37 kB │ gzip: 0.26 kB
dist/assets/picocolors.browser-v4etCjPf.js  0.88 kB │ gzip: 0.53 kB
dist/assets/index-CyfVNW-F.js               2.21 kB │ gzip: 1.03 kB
✓ built in 60ms

❌ with "hoistingLimits": "dependencies"

{
  "installConfig": {
    "hoistingLimits": "dependencies"
  }
}

yarn && yarn run build

vite v5.0.12 building for production...
✓ 12 modules transformed.
dist/index.html                             0.37 kB │ gzip: 0.27 kB
dist/assets/_commonjsHelpers-HFhYSYcO.js    0.12 kB │ gzip: 0.13 kB
dist/assets/picocolors.browser-9Ml1HsQB.js  0.82 kB │ gzip: 0.52 kB
dist/assets/picocolors.browser-qHnddVYe.js  0.82 kB │ gzip: 0.52 kB
dist/assets/index-x95LGN1s.js               2.33 kB │ gzip: 1.08 kB
✓ built in 65ms

Version

Package Version
"yarn" 4.1.0
"vite" "5.0.12"
"picolors" "1.0.0"

Shasums

shasum packages/vitejs-investigation-app/node_modules/picocolors/package.json

454b9f0ccd76446f9e066ce236d35ebd33e49a5c packages/vitejs-investigation-app/node_modules/picocolors/package.json

shasum packages/vitejs-investigation-dynamic-import/node_modules/picocolors/package.json

454b9f0ccd76446f9e066ce236d35ebd33e49a5c packages/vitejs-investigation-dynamic-import/node_modules/picocolors/package.json