> Markdown version of [Vite](https://vaadin.com/docs/next/flow/configuration/development-mode/vite). Section index: [llms.txt](https://vaadin.com/docs/next/flow/llms.txt)

# Vite

Vaadin uses [Vite](https://vite.dev/) to build and serve the frontend of an application: the JavaScript, TypeScript, and CSS that the application and its add-ons use. Vite runs on [Node.js](https://vaadin.com/docs/next/flow/configuration/development-mode/node-js.md) and is installed into `node_modules` by the [frontend package manager](https://vaadin.com/docs/next/flow/configuration/development-mode/npm-pnpm-bun.md), like any other frontend package.

## <a id="when-vite-runs"></a>When Vite Runs

Vite runs in the following situations:

- **Frontend development server.** With `frontend.hotdeploy` set to `true`, Vaadin starts the Vite development server together with the application. It serves the frontend files to the browser and reloads them when they change. See [Disabling the Pre-Compiled Bundle](https://vaadin.com/docs/next/flow/configuration/development-mode.md#disable-precompiled-bundle).

- **Development bundle.** When the application has frontend customizations, Vaadin runs a Vite build to create an application-specific development bundle. See [Faster Starts by Pre-Compiling](https://vaadin.com/docs/next/flow/configuration/development-mode.md#precompiled-bundle).

- **Production bundle.** When the application has frontend customizations, the production build runs a Vite build to create an optimized production bundle. See [Production Build](https://vaadin.com/docs/next/flow/production/production-build.md).

Without the frontend development server, an application that has no frontend customizations uses a pre-compiled bundle. In that case, Vite doesn’t run, and your Vite configuration has no effect.

## <a id="configuration-files"></a>Configuration Files

Vaadin creates two Vite configuration files in the project root:

- `vite.generated.ts`

  The configuration that every Vaadin application needs. Vaadin overwrites this file on every build, so don’t edit it.

- `vite.config.ts`

  The configuration file that Vite reads. It imports the configuration from `vite.generated.ts`, and is where you put your own settings. Vaadin creates the file when it doesn’t exist, and replaces it with the current default as long as you haven’t modified it. Once you’ve customized it, commit it to source control — see [Source Control](https://vaadin.com/docs/next/flow/configuration/source-control.md).

The default `vite.config.ts` looks like this:

`vite.config.ts`

```typescript
import { UserConfigFn } from 'vite';
import { overrideVaadinConfig } from './vite.generated.ts';

const customConfig: UserConfigFn = (env) => ({
  // Here you can add custom Vite parameters
  // https://vitejs.dev/config/
});

export default overrideVaadinConfig(customConfig);
```

## <a id="customizing"></a>Customizing the Configuration

Add your settings to the object that `customConfig` returns. They can be any of the [Vite configuration options](https://vite.dev/config/).

The `overrideVaadinConfig()` function merges your settings into Vaadin’s configuration with Vite’s [`mergeConfig()`](https://vite.dev/guide/api-javascript#mergeconfig) function:

- A value that you set replaces Vaadin’s value for the same option.

- Objects are merged option by option, so you only need to set the options you change.

- Arrays are concatenated. For example, plugins in your `plugins` array are added after Vaadin’s own plugins.

For example, the following configuration adds an import alias for a folder of shared frontend code:

`vite.config.ts`

```typescript
import path from 'node:path';
import type { UserConfigFn } from 'vite';
import { overrideVaadinConfig } from './vite.generated.ts';

const customConfig: UserConfigFn = (env) => ({
  resolve: {
    alias: {
      '@shared': path.resolve(import.meta.dirname, 'src/main/frontend/shared')
    }
  }
});

export default overrideVaadinConfig(customConfig);
```

The `env` argument tells where the configuration is used. Its `command` property is `serve` for the frontend development server, and `build` when a development or production bundle is built.

Vaadin doesn’t take `vite.config.ts` into account when it checks whether an existing bundle is up to date. A change to the file alone therefore doesn’t make Vaadin build a new bundle. To build a new development bundle with the changed configuration, delete the `src/main/bundles/dev.bundle` file and the `dev-bundle` folder in the build directory (i.e., `target` for Maven, `build` for Gradle). To build a new production bundle, run the build with `-Dvaadin.force.production.build=true`.

Pages that need a specific Vite setting show it in their own context:

- [Source Maps in Production](https://vaadin.com/docs/next/flow/production/source-maps.md) enables source maps for a production bundle.

- [Testing](https://vaadin.com/docs/next/hilla/guides/testing.md) reuses Vaadin’s Vite configuration for Vitest.

## <a id="related-settings"></a>Related Settings

The following Vaadin settings affect how Vaadin runs Vite:

- The `devmode.vite.options` [configuration property](https://vaadin.com/docs/next/flow/configuration/properties.md) passes extra command-line options to the Vite development server. Separate the options with spaces, for example `-Dvaadin.devmode.vite.options="--debug"`.

- The `frontendExtraFileExtensions` plugin parameter adds file extensions, such as `scss`, to the files that go into a bundle. See [Faster Starts by Pre-Compiling](https://vaadin.com/docs/next/flow/configuration/development-mode.md#precompiled-bundle).

- The Maven and Gradle plugin parameters set the folder that Vite writes a bundle to, and the folders that Vaadin collects frontend files from. See [Maven Configuration Properties](https://vaadin.com/docs/next/flow/configuration/maven.md) and [Gradle Configuration Properties](https://vaadin.com/docs/next/flow/configuration/gradle.md).
