skip to content

Vite

Vite serves source as native ES modules in development and ships a Rolldown bundle with Oxc transforms in production. Interviewers ask because the gap left between the two explains most surprises.

on this pageshow

explore

questions

page 2 of 2

After a Vite config sets `css.transformer: 'lightningcss'`, why do postcss.config.js plugins and `css.modules` naming options silently stop applying?

level: seniorimportance: nice to knowfreq 4%

basics

~20 s

css.transformer picks the engine for CSS processing. With 'lightningcss', Vite hands each stylesheet to Lightning CSS instead of PostCSS, so PostCSS config and plugins never run, and CSS Modules naming moves to css.lightningcss.cssModules; css.modules feeds postcss-modules only.

open as a page

In Vite 8.1 and later, a dev server reached through an HTTPS reverse proxy serves pages but never hot-updates; how does server.ws fix the HMR socket?

level: seniorimportance: nice to knowfreq 4%

basics

~20 s

Vite's HMR client opens a WebSocket to the page's own host and port, so a proxy that does not forward WebSocket upgrades breaks it. Proxy WebSockets too, or set server.ws options such as clientPort, which Vite 8.1 moved from server.hmr.

open as a page

With Vite 8.1 or later, how do `import { plan } from './planner.wasm'` and `./planner.wasm?init` differ, and when do you need `?url` instead?

level: seniorimportance: nice to knowfreq 4%

basics

~20 s

Since Vite 8.1 a direct .wasm import is instantiated by Vite and exposes the module's exports as named ES exports. ?init returns a function that instantiates on demand with your imports. Use ?url when you need the WebAssembly.Module itself.

open as a page

When porting an in-house Rollup-style plugin to Vite 8, why add hook filters, when should load or transform return moduleType: 'js', and which Rollup hooks stop running?

level: seniorimportance: nice to knowfreq 3%

basics

~20 s

In Vite 8, Rolldown calls JavaScript plugins from Rust, so hook filters let it skip unrelated modules. A load or transform turning another type into JavaScript should return moduleType: 'js'. shouldTransformCachedModule, resolveImportMeta and renderDynamicImport no longer run.

open as a page

After upgrading to Vite 8, `import Recur from 'recur-rules'` (a CommonJS package compiled from ESM) in an app with `"type": "module"` yields an object holding `default`, not the function; why, and what fixes it?

level: seniorimportance: nice to knowfreq 5%

basics

~20 s

Vite 8 makes the default import of a CommonJS module equal module.exports whenever the importer is .mjs or .mts or its package.json declares type: module, even if the module sets __esModule. Read .default explicitly, or get the package fixed.

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

showing 31–36 of 36