[PR #746] [MERGED] fix(build): eliminate Vite 8 treeshake.preset warning #812

Closed
opened 2026-05-06 13:10:14 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/746
Author: @Divkix
Created: 4/2/2026
Status: Merged
Merged: 4/2/2026
Merged by: @james-elicx

Base: mainHead: fix/vite8-treeshake-preset-warning


📝 Commits (4)

  • 4b6c58a fix(build): eliminate Vite 8 treeshake.preset warning
  • 63152c2 refactor(build): address PR review feedback for treeshake config
  • 90dd87f docs(build): clarify Rolldown treeshake divergence in comments
  • 146475e chore: address PR review feedback on treeshake config

📊 Changes

3 files changed (+79 additions, -30 deletions)

View changed files

📝 examples/app-router-playground/vite.config.ts (+0 -23)
📝 packages/vinext/src/index.ts (+47 -5)
📝 tests/build-optimization.test.ts (+32 -2)

📄 Description

Summary

Fixes #540 - Vite 8 builds produce warnings about the deprecated "treeshake.preset" option.

Problem

The "treeshake.preset" option is Rollup-specific and not supported by Rolldown (Vite 8's bundler). This causes build warnings:

Warning: Invalid input options (1 issue found)
- For the "treeshake.preset". Invalid key: Expected never but received "preset".

Solution

Added version-gated "getClientTreeshakeConfigForVite(viteMajorVersion)" function that returns:

  • Vite 7: { preset: "recommended", moduleSideEffects: "no-external" } (Rollup-compatible)
  • Vite 8+: { moduleSideEffects: "no-external" } (Rolldown-compatible, no preset)

The "moduleSideEffects: "no-external"" option is valid in both bundlers and provides the key optimization for barrel-exporting libraries.

Changes

  • Added "getClientTreeshakeConfigForVite(viteMajorVersion)" function
  • 🔄 Updated 4 usage sites to use version-gated function
  • 📋 Marked "clientTreeshakeConfig" as @deprecated for backward compatibility
  • 📤 Exported new function for testing
  • 🧪 Added comprehensive tests for Vite 7/8/9+ compatibility
  • Updated existing tests to expect Vite 8 format

Testing

  • All 71 build-optimization tests pass
  • No treeshake.preset warnings in Vite 8 builds
  • Tree-shaking still effective (verified with example builds)
  • Lint and type checks pass

Backward Compatibility

  • The existing "clientTreeshakeConfig" export is preserved with @deprecated notice
  • External consumers can migrate to the new version-gated function when ready

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/746 **Author:** [@Divkix](https://github.com/Divkix) **Created:** 4/2/2026 **Status:** ✅ Merged **Merged:** 4/2/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/vite8-treeshake-preset-warning` --- ### 📝 Commits (4) - [`4b6c58a`](https://github.com/cloudflare/vinext/commit/4b6c58a825ecc576ae081357fcdc41bc17f7c4ef) fix(build): eliminate Vite 8 treeshake.preset warning - [`63152c2`](https://github.com/cloudflare/vinext/commit/63152c2a7eb6a2e5bf72c584441c921ed84e06f5) refactor(build): address PR review feedback for treeshake config - [`90dd87f`](https://github.com/cloudflare/vinext/commit/90dd87f6bd14c4a9a4ecda3a916c0d1575153b05) docs(build): clarify Rolldown treeshake divergence in comments - [`146475e`](https://github.com/cloudflare/vinext/commit/146475e268bb0cb9231cb31448a9af73dc1d1c06) chore: address PR review feedback on treeshake config ### 📊 Changes **3 files changed** (+79 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `examples/app-router-playground/vite.config.ts` (+0 -23) 📝 `packages/vinext/src/index.ts` (+47 -5) 📝 `tests/build-optimization.test.ts` (+32 -2) </details> ### 📄 Description ## Summary Fixes #540 - Vite 8 builds produce warnings about the deprecated "treeshake.preset" option. ## Problem The "treeshake.preset" option is Rollup-specific and not supported by Rolldown (Vite 8's bundler). This causes build warnings: ``` Warning: Invalid input options (1 issue found) - For the "treeshake.preset". Invalid key: Expected never but received "preset". ``` ## Solution Added version-gated "getClientTreeshakeConfigForVite(viteMajorVersion)" function that returns: - **Vite 7**: `{ preset: "recommended", moduleSideEffects: "no-external" }` (Rollup-compatible) - **Vite 8+**: `{ moduleSideEffects: "no-external" }` (Rolldown-compatible, no preset) The "moduleSideEffects: "no-external"" option is valid in both bundlers and provides the key optimization for barrel-exporting libraries. ## Changes - ✨ Added "getClientTreeshakeConfigForVite(viteMajorVersion)" function - 🔄 Updated 4 usage sites to use version-gated function - 📋 Marked "clientTreeshakeConfig" as @deprecated for backward compatibility - 📤 Exported new function for testing - 🧪 Added comprehensive tests for Vite 7/8/9+ compatibility - ✅ Updated existing tests to expect Vite 8 format ## Testing - [x] All 71 build-optimization tests pass - [x] No treeshake.preset warnings in Vite 8 builds - [x] Tree-shaking still effective (verified with example builds) - [x] Lint and type checks pass ## Backward Compatibility - The existing "clientTreeshakeConfig" export is preserved with @deprecated notice - External consumers can migrate to the new version-gated function when ready --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:10:14 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#812
No description provided.