ARTICLE - Dev Stack & Tools

How Vite Handles Development and Production Builds

Vite's speed is not just native ESM: on-demand transforms, dependency optimization and production builds have different boundaries. Check the target version and plugins; a working dev server does not validate the production bundle.

2026-08-06 16IDC Original 65 views
Advertisement

Vite's dev server and production build solve different problems: development transforms modules on demand for the browser, while the builder for that major version emits static assets. When a project works locally but fails after deployment, check its version, plugins and built output first; a running dev server is not production validation. This article focuses on the current Vite 8 documentation and notes where older versions differ. Check the official migration guide when versions change.

For more tooling context, browse the frontend building category; the frontend toolchain comparison covers migration considerations across tools.

Vite development and production build flows Dev server Source and deps On-demand transforms Browser modules Production build Source and plugins Vite 8: Rolldown Static build output Scope: Vite 8 official guide; older majors use different optimizers and builders
Figure 1: Vite development and production build flows (Source: Vite 8 official guide; older majors use different optimizers and builders)

What the dev server and HMR do

The project-root index.html is the Vite app entry point. The dev server transforms requested source, resolves dependencies and serves browser-loadable modules on demand. Dependency optimization handles bare imports and some CommonJS/UMD packages. Vite 8 documentation says dependency optimization uses Rolldown; defaults and configuration differ in Vite 7, so do not project one version's internals onto every Vite project.

HMR applies module updates without a full reload where the framework integration and update boundary allow it. If an update cannot be applied safely, Vite may reload the page. For an HMR failure, confirm that the changed file is imported by the active page, then inspect the browser console and Vite terminal for the invalidated module. "Millisecond-level" updates are not a performance guarantee for every project.

Production builds and version differences

Vite 8 uses Rolldown and Oxc-based tooling for builds and transforms; Vite 7's default production bundler is Rollup. When moving older configuration, plugins or esbuild options to Vite 8, check each item against that version's migration guide. A plugin's Rollup compatibility label alone does not establish that every hook and option works with the target Vite/Rolldown version.

Major version Default production builder Check before upgrading
Vite 7 Rollup Existing Rollup plugins and build options
Vite 8 Rolldown Migration notes, plugin hooks and older config compatibility

A working dev server only validates the development path. Build the project and preview the output to check deployed paths, assets, dynamic imports and key pages. For a subpath deployment, make sure base matches the hosting path. Type checking should also be separate from Vite's transforms; many projects run tsc --noEmit through their own script.

Configure a proxy and verify the build

server.proxy configures request forwarding in the dev server; it is not included as a production proxy. This example forwards /api to a local backend. Replace target if needed and make sure the backend is running.

import { defineConfig } from 'vite'

export default defineConfig({
  server: {
    port: 5173,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:8080',
        changeOrigin: true,
      },
    },
  },
})

You should see: after npm run dev, a request to http://localhost:5173/api/health should return the expected backend health response. If the connection is refused, check the backend's listen address and port. If port 5173 is occupied, Vite may use the next available port by default; use the address printed in the terminal.

Use the project's build script; a common setup can run npx vite build, followed by npx vite preview to inspect the output. You should see: the build completes, the preview loads the intended route and assets, and the browser console has no critical runtime errors. This still does not validate production hosting, a CDN or every target browser.

Environment variables and client-side secrets

Vite's mode determines which .env files are loaded, and client code reads allowed variables through import.meta.env. By default, only variables prefixed with VITE_ are exposed to client code. Treat them as public: do not put API keys, database passwords or other credentials in them. Values used only by the config file, such as a proxy target, should not be exposed through define or another client injection mechanism.

For example, .env.production can hold a public API base URL:

VITE_API_BASE=https://api.example.com

You should see: after npx vite build, the app can read the address through import.meta.env.VITE_API_BASE. Because the value is included in client output, any visitor can read it. After changing a variable, restart the dev server or rebuild, and confirm the selected mode matches the relevant .env.[mode] file.

Limitations

  • A Vite major version can change its dependency optimizer, builder and transformer; check the official migration guide and plugin compatibility before upgrading.
  • server.* configures the dev server, not production hosting; a local proxy does not replace an online API gateway or reverse proxy.
  • Variables with the VITE_ prefix are public client configuration, not secrets. Keep credentials on a server.
  • vite preview previews a local build; it is not a production hosting server or a substitute for production validation.
  • This guide does not cover SSR, framework-specific deployment or library mode; use the relevant framework and Vite configuration docs for those cases.

FAQ

Why can older rollupOptions settings fail in Vite 8?

Do not assume so. Vite 8 uses Rolldown, while earlier major versions used Rollup by default; older options or plugins may need changes. Check the Vite 8 migration guide and the plugin's compatibility notes, then build and preview from a separate branch. A config file that parses does not prove that output behavior is unchanged.

Can VITE_API_KEY store a browser-side secret?

No. Variables prefixed with VITE_ are bundled into client code and can be read by visitors; use them only for public configuration such as an API base URL. Keep confidential credentials in a backend or controlled server-side function, rather than relying on variable names or minified output to hide them.

Which Vite major version's build config should I check before upgrading?

Check the target major first: Vite 7 and 8 use different builders. Vite 7 defaults to Rollup; Vite 8 uses Rolldown. Check old plugins, build options and migration notes, then run a production build and vite preview to check routes, assets and console errors. A config that parses does not prove plugin behavior is compatible.

Related Providers

  • Vite: use its documentation entry for configuration, plugins and version notes.
  • npm: use it to install dependencies from the lockfile and reproduce a local build.

References

Community & Resources

  • Dev tools: explore engineering tools beyond frontend build systems.
  • Vite guide: official getting-started, dev-server and production-build documentation.

Original source: 16IDC Original ↗