Skip to content

Conversation

@reeseo3o
Copy link

@reeseo3o reeseo3o commented Jan 23, 2026

What / Why

Custom environments default to consumer: 'server' (SSR), which caused library filename resolution to be unintentionally bypassed in lib mode.

Reproduction

Config

export default {
  environments: {
    client: {
      build: {
        lib: {
          fileName: 'index.root',
        },
      },
    },
    browser: {
      build: {
        lib: {
          fileName: (format) => `index.browser.${format}.js`,
        },
      },
    },
  },
}

Expected

  • Each environment respects its own build.lib.fileName (including function form).

Actual

  • client (ssr=false, libOptions=true) -> fileName callback is called.
  • browser (ssr=true, libOptions=true) -> fileName callback is not called.
    Example output option difference
  • client: { entryFileNames: [Function] }
  • browser: { entryFileNames: "[name].js" }

Root Cause

In packages/vite/src/node/build.ts, entryFileNames selected the SSR naming pattern before checking libOptions, so library filename resolution (resolveLibFilename) never ran when ssr === true.

Fix

Prefer library mode (libOptions) over SSR when deciding entryFileNames, ensuring that resolveLibFilename(...) is used whenever build.lib is enabled (even if ssr === true).

Tests

  • Added a unit test that builds multiple environments and asserts that
    environment-specific build.lib.fileName callbacks are invoked per environment and per format.
  • Test: packages/vite/src/node/tests/build.spec.ts

Verification

  • pnpm --filter vite build
  • pnpm vitest run packages/vite/src/node/tests/build.spec.ts

Issue

Closes #21445

@reeseo3o reeseo3o changed the title fix: respect build.lib.fileName in custom environments (fix #21445) Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant