[GH-ISSUE #538] Per-environment optimizeDeps overrides top-level exclude entries set by other Vite plugins #112

Closed
opened 2026-05-06 12:37:19 +02:00 by BreizhHardware · 0 comments

Originally created by @Jbithell on GitHub (Mar 14, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/538

When a Vite plugin (e.g. @lingui/vite-plugin) adds packages to the top-level optimizeDeps.exclude during its config hook, vinext's per-environment optimizeDeps configuration replaces those entries entirely. This forces downstream projects to add a secondary Vite plugin that runs after vinext to re-patch each environment's exclude list.

Repro:

  1. Use a Vite plugin that calls config.optimizeDeps.exclude.push(...) (e.g. @lingui/vite-plugin excludes @lingui/macro, @lingui/core/macro, @lingui/react/macro)
  2. Run vinext dev
  3. The excluded packages get pre-bundled anyway because vinext's per-environment config overwrites the top-level excludes

Current workaround:

// Runs after vinext to re-add excludes to each environment
function environmentOptimizeDepsFix() {
  return {
    name: "environment-optimize-deps-fix",
    config(config) {
      if (!config.environments) return;
      for (const [, env] of Object.entries(config.environments)) {
        if (env?.optimizeDeps) {
          env.optimizeDeps.exclude = [
            ...(env.optimizeDeps.exclude || []),
            "@lingui/macro",
            "@lingui/core/macro",
            "@lingui/react/macro",
          ];
        }
      }
    },
  };
}

Expected:

vinext should merge top-level optimizeDeps.exclude entries into its per-environment configs rather than replacing them.

Originally created by @Jbithell on GitHub (Mar 14, 2026). Original GitHub issue: https://github.com/cloudflare/vinext/issues/538 When a Vite plugin (e.g. `@lingui/vite-plugin`) adds packages to the top-level `optimizeDeps.exclude` during its `config` hook, vinext's per-environment `optimizeDeps` configuration replaces those entries entirely. This forces downstream projects to add a secondary Vite plugin that runs after vinext to re-patch each environment's exclude list. ## Repro: 1. Use a Vite plugin that calls `config.optimizeDeps.exclude.push(...)` (e.g. `@lingui/vite-plugin` excludes @lingui/macro, @lingui/core/macro, @lingui/react/macro) 2. Run `vinext dev` 3. The excluded packages get pre-bundled anyway because vinext's per-environment config overwrites the top-level excludes ## Current workaround: ```typescript // Runs after vinext to re-add excludes to each environment function environmentOptimizeDepsFix() { return { name: "environment-optimize-deps-fix", config(config) { if (!config.environments) return; for (const [, env] of Object.entries(config.environments)) { if (env?.optimizeDeps) { env.optimizeDeps.exclude = [ ...(env.optimizeDeps.exclude || []), "@lingui/macro", "@lingui/core/macro", "@lingui/react/macro", ]; } } }, }; } ``` ## Expected: vinext should merge top-level `optimizeDeps.exclude` entries into its per-environment configs rather than replacing them.
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#112
No description provided.