Vite Build Configuration#
The Strapi admin's Vite configuration is centralized in packages/core/strapi/src/node/vite/config.ts. It exports three functions consumed by the build pipeline:
resolveBaseConfig— shared base configuration applied to all modesresolveProductionConfig— extends base with minification, sourcemaps, and a single Rollup entry point (strapi)resolveDevelopmentConfig— extends base with HMR, middleware mode, monorepo aliases, andallowedHosts: truefor reverse-proxy compatibility
User overrides are supported via a vite.config.{js,mjs,ts,mts} file placed in src/admin/. The mergeConfigWithUserConfig function loads the first matching file and calls it as a transform function (config: UserConfig) => UserConfig, letting projects augment but not fully replace the base config .
Dependency Pre-Bundling (optimizeDeps.include)#
Vite pre-bundles the following dependencies to guarantee a single ESM instance is resolved across all chunks — including lazily-loaded plugin chunks :
| Group | Packages | Reason |
|---|---|---|
| React core | react, react/jsx-runtime, react-dom/client | Prevents the duplicate React warning |
| Styling / routing | styled-components, react-router-dom | Shared context across the app |
| Redux stack | react-redux, @reduxjs/toolkit | Admin and RTK Query share one Redux context; a second copy causes "could not find react-redux context value" |
| Design system | @strapi/design-system, @radix-ui/react-tooltip | Plugin chunks must inherit TooltipProvider/DesignSystemProvider context from the root |
| Utilities | lodash, prismjs | CJS-only libs need ESM conversion; prismjs otherwise exposes an empty namespace in plugin chunks |
When @strapi/design-system is symlinked (via portal:, file:, or yarn link), it is excluded from pre-bundling and added to exclude instead, so local changes are reflected without clearing the cache .
Extra packages for the internal monorepo example app are gated behind a UUID check (isMonorepoExampleApp) and are never pre-bundled in real user apps .
Deduplication and Alias Resolution#
Two additional mechanisms reinforce the single-instance guarantee:
resolve.dedupe — tells Vite/Rollup to always resolve these packages to the same copy: react, react-dom, react-router-dom, styled-components, react-redux, @reduxjs/toolkit, @strapi/design-system, @radix-ui/react-tooltip, lodash.
resolve.alias — maps each package name to an explicit filesystem path via getModulePath. This is specifically required under pnpm's strict dependency isolation, where plugin chunks may not be able to walk up to a hoisted copy of a shared package .
Together, pre-bundling + dedupe + alias form a three-layer defence against duplicate module instances.
Redux Duplicate Context Fix (PR #26249)#
react-redux and @reduxjs/toolkit were added to all three mechanisms — optimizeDeps.include, resolve.dedupe, and resolve.alias — in PR #26249 to fix a post-upgrade regression where stale Vite cache entries caused the admin panel to load a second copy of the Redux context, producing a runtime crash. The same PR extended the upgrade CLI to offer to delete node_modules/.strapi/vite after dependency installation , with deletion gated behind user confirmation to avoid unexpected build slowdowns .
Development-Mode Extras#
In development, resolveDevelopmentConfig adds:
- Monorepo aliases via
getMonorepoAliases— maps@strapi/admin/strapi-adminand other internal packages directly tosrc/for hot rebuilds without a separate watcher. - HMR on Strapi's HTTP server — reuses
ctx.strapi.server.httpServerso websocket connections work behind reverse proxies that only expose the Strapi port . appType: 'custom'andmiddlewareMode: true— embeds Vite as middleware inside the Strapi server process .
Key Files#
| File | Purpose |
|---|---|
packages/core/strapi/src/node/vite/config.ts | Main Vite config factory |
packages/core/strapi/src/node/core/resolve-module.ts | getModulePath — resolves package roots for aliases |
packages/core/strapi/src/node/core/aliases.ts | getMonorepoAliases — dev-mode monorepo path mappings |
packages/core/strapi/src/node/create-build-context.ts | BuildContext — assembles plugins, options, env for the build |
packages/utils/upgrade/src/modules/upgrader/upgrader.ts | Post-upgrade Vite cache clearing logic |