skip to content

Production Bundling

vite build runs Rolldown: build.rolldownOptions, codeSplitting groups, library mode and an Oxc target defaulting to baseline-widely-available. Interviewers ask because chunking sets bundle cost.

on this pageshow

questions

6

In Vite 8, what does running `vite build` on a single-page app do by default, from the entry it reads to the files it writes?

level: juniorimportance: must knowfreq 24%

answer

  1. one HTML file starts it
  2. a Rust bundler replaced Rollup
  3. one engine lowers and minifies JavaScript
  4. hashed names under one folder
  5. maps off, public/ copied

basics

~20 s

vite build takes index.html as its entry, bundles the module graph with Rolldown, lowers and minifies JavaScript with Oxc and CSS with Lightning CSS, and writes content-hashed files into dist/assets, with no source maps unless build.sourcemap is set.

solid answer

~40 s

`vite build` starts from `<root>/index.html`, follows every import through the plugin pipeline and hands the graph to Rolldown, which in Vite 8 replaced Rollup as the production bundler. Oxc transforms the JavaScript and lowers it to `build.target`, whose default `'baseline-widely-available'` means Chrome and Edge 111, Firefox 114 and Safari 16.4, then minifies it (`build.minify: 'oxc'`); Lightning CSS minifies the CSS (`build.cssMinify: 'lightningcss'`). The output goes to `build.outDir` (`dist`), emptied first when it sits inside the root: entry and chunk files land in `assets/` as `[name]-[hash].js`, the HTML is rewritten to point at them, and `public/` is copied as it is. Source maps are off (`build.sourcemap: false`), no polyfills are added, and the build prints gzip sizes and warns about any chunk above 500 kB.

go deeper

for a junior

Recall the path: index.html in, Rolldown bundles, Oxc lowers and minifies JavaScript, Lightning CSS minifies CSS, hashed files out in dist/assets, no maps by default.

for a middle

Explain each default by its option name and value, especially build.target's baseline-widely-available browsers and the separate JavaScript and CSS minifiers, and what public/ copying means for asset URLs.

for a senior

Show you can read a dist folder and trace each file back to the option that made it, and that you know which Vite 7 settings change meaning or need extra installs after an upgrade.

for a principal

Frame defaults as a platform decision: which build options every app inherits from a shared config, which ones teams may override, and how you catch a default that changed in a new major.

## What `vite build` does, step by step `vite build` is the command that turns a Vite project into static files a web server can hand to browsers. For a **single-page app** with default options it runs these stages: 1. **Read the entry.** The default entry is `<root>/index.html`. Vite parses it and treats its `<script type="module">` tags and stylesheet links as the roots of the **module graph** (the set of every file reachable through imports). 2. **Resolve and transform each module.** Every `import` is resolved and passed through the plugin pipeline: framework plugins, CSS handling, asset imports and your own plugins. 3. **Bundle with Rolldown.** In Vite 8 the bundler is **Rolldown**, a Rust bundler with a Rollup-compatible plugin API. It produces an entry chunk, a chunk for each dynamic `import()` and chunks for shared code. 4. **Transform and lower with Oxc.** JavaScript and TypeScript go through the **Oxc** transformer, which rewrites syntax newer than `build.target` allows. The build warns about features Oxc cannot lower safely. 5. **Minify.** The **Oxc minifier** compresses JavaScript and **Lightning CSS** compresses CSS. 6. **Write the output.** Files go to `build.outDir` under `build.assetsDir`, named `[name]-[hash].js` and `[name]-[hash].css`; the HTML is rewritten to reference them, and the contents of `public/` are copied untouched. 7. **Report.** Vite lists every file with its size and gzip size, and warns about chunks larger than `build.chunkSizeWarningLimit`. ## The engines Vite 8 changed Most older answers describe Vite 7. The jobs are the same; the tools doing them are not. | Job | Vite 8 | Vite 7 | |---|---|---| | Bundling the production build | Rolldown | Rollup | | JavaScript transforms and lowering | Oxc | esbuild | | Default JavaScript minifier | Oxc minifier | esbuild | | Default CSS minifier | Lightning CSS | esbuild | | Option for the bundler's own settings | `build.rolldownOptions` | `build.rollupOptions` (now a deprecated alias) | ## Defaults that shape the output | Option | Default | Effect | |---|---|---| | `build.outDir` | `dist` | emptied before writing when it is inside the root (`build.emptyOutDir`) | | `build.assetsDir` | `assets` | folder for hashed JavaScript, CSS and emitted assets | | `build.target` | `'baseline-widely-available'` | `['chrome111', 'edge111', 'firefox114', 'safari16.4', 'ios16.4']` | | `build.minify` | `'oxc'` for a client build, `false` for an SSR build | JavaScript minification | | `build.cssMinify` | `'lightningcss'` | becomes `false` when `build.minify` is turned off for a client build | | `build.sourcemap` | `false` | no `.map` files | | `build.cssCodeSplit` | `true` | CSS imported by an async chunk becomes its own file, loaded with that chunk | | `build.copyPublicDir` | `true` | `public/` copied into `dist` | | `build.chunkSizeWarningLimit` | `500` | kB, compared with the uncompressed size; a warning, not an error | The `'baseline-widely-available'` target is fixed for each major release; for Vite 8 it is the Baseline Widely Available set as of 2026-01-01, up from Chrome 107, Firefox 104 and Safari 16.0 in Vite 7. ## What it does not do - **No polyfills.** Vite lowers syntax only. A runtime API the target browser lacks still needs a polyfill you add, or the legacy plugin. - **No source maps** unless `build.sourcemap` is `true` (separate files), `'inline'` (a data URI in each file) or `'hidden'` (separate files without the comment that links them). - **No production server.** `dist` is plain static output; `vite preview` only serves it locally for a check. - **No rebuild on change** unless you run `vite build --watch`. ## Mistakes worth avoiding - **Expecting `public/` to be processed.** Files there are copied verbatim, keep their names and are referenced by absolute path; only imported assets get hashed names. - **Treating the 500 kB warning as a failure.** It only reports; the build still succeeds, and raising the limit hides the signal rather than fixing a large chunk. - **Carrying a Vite 7 minifier setting forward.** `build.minify: 'esbuild'` is deprecated in Vite 8 and needs `esbuild` installed as a devDependency, because Vite no longer depends on it; `'terser'` likewise needs `terser` installed. - **Assuming SSR output is minified.** `build.minify` defaults to `false` for an SSR build, so server code stays readable. Knowing these defaults lets you read a `dist` folder and say which option produced each file, which is what most interviewers are checking when they ask what the command does.

  • You want readable stack traces in an error tracker but do not want the shipped files to point browsers at their maps. Which `build.sourcemap` value fits?
    `'hidden'`. It writes the same separate `.map` files as `true` but suppresses the source-map comment in each bundled file, so nothing in the shipped JavaScript links to them; you upload the maps to the tracker and keep them off the public server. `true` writes the files and the comment, and `'inline'` embeds each map as a data URI inside the file itself.
  • A Vite 7 config sets `build.minify: 'esbuild'` and `esbuild.drop: ['console']`. What happens after the upgrade to Vite 8?
    `build.minify: 'esbuild'` still works but is deprecated, and the build needs `esbuild` installed as a devDependency because Vite 8 no longer depends on it. The `esbuild` option is deprecated in favour of `oxc`; for dropping calls, the migration guide points to `build.rolldownOptions.output.minify.compress.drop*` with the default Oxc minifier. Property-mangling options have no Oxc equivalent.
  • The build prints a warning that some chunks are larger than 500 kB. Has it failed, and what controls the threshold?
    It has not failed. `build.chunkSizeWarningLimit` (default `500`, in kB, measured on the uncompressed size) only decides when Vite warns. The useful response is to find out why the chunk is large and split it, for example with lazy routes or chunk groups; raising the limit just silences the report.

  • Vite builds for production with Rollup and minifies with esbuild by default
  • vite build emits source maps unless you turn them off
  • build.target makes Vite add polyfills for missing browser APIs
  • Files in public/ are hashed and bundled like imported assets
  • The chunk-size warning fails the build at 500 kB
  • SSR builds are minified by default just like client builds

Assumes Vite 8, where Rolldown replaced Rollup for the build, Oxc replaced esbuild for transforms and JavaScript minification, and Lightning CSS became the default CSS minifier.

open as a page

In Vite 8, how do you move an app's `node_modules` code into separate named chunks, and what happened to object-form `manualChunks`?

level: middleimportance: should knowfreq 14%

basics

~20 s

Vite 8 configures chunk groups in build.rolldownOptions.output.codeSplitting: each group has a name and, usually, a test that captures matching module ids. Object-form manualChunks was removed, the function form is deprecated, and build.rollupOptions is only a deprecated alias.

open as a page

In a Vite production build, what does Vite add around a dynamic `import()`, and when does it fire the `vite:preloadError` event?

level: middleimportance: should knowfreq 8%

basics

~20 s

Vite rewrites each code-split dynamic import() with a preload step that fetches the chunk's imported chunks and CSS in parallel; if loading fails, it dispatches vite:preloadError on window, with the original error in event.payload, and event.preventDefault() stops that error being thrown.

open as a page

In Vite 8 library mode, what does `build.lib` emit by default for a single-entry widget, and how do you keep the framework out of its bundle?

level: seniorimportance: should knowfreq 7%

basics

~20 s

With one entry, build.lib emits an ES module and a UMD file named after package.json's name, plus one CSS file if it imports CSS, with every asset inlined. The framework is bundled unless listed in build.rolldownOptions.external, with a UMD global in output.globals.

open as a page

With Vite 8, when is lowering `build.target` enough for an older browser, and when do you need `@vitejs/plugin-legacy` instead?

level: seniorimportance: should knowfreq 9%

basics

~20 s

Lowering build.target is enough when the browser has native ES module dynamic import and import.meta and lacks only newer syntax, since it adds no polyfills. Below that floor you need @vitejs/plugin-legacy, which adds nomodule legacy chunks and a polyfill chunk.

open as a page

In Vite, how does an SSR build made with `vite build --ssr` differ from the client build, and when do you add a dependency to `ssr.noExternal`?

level: seniorimportance: nice to knowfreq 5%

basics

~20 s

vite build --ssr builds a server entry that Node loads with import(): dependencies stay external, output is unminified, and assets are left to the client build. Add a dependency to ssr.noExternal when Node cannot import it as published, so Vite must bundle it.

open as a page