Vite Config
Every Tempest frontend app starts with the same vite.config.ts: the React
plugin, the @ → src alias, and the dev-server defaults. Copying that block
from app to app is tedious, easy to get wrong, and drifts over time. The
createViteConfig helper kills that boilerplate: you call one function, get a
ready-made config object back, and assign it straight to export default.
// vite.config.ts
import { createViteConfig } from "tempest-react-sdk/vite";
export default createViteConfig({
proxy: { "/api": "http://127.0.0.1:8000" },
});
That's it. React plugin wired, @ resolving to src, dev server listening on
127.0.0.1:5173, and /api calls forwarded to your local backend — all in four
lines.
The tempest-react-sdk/vite subpath
Look at the import: it comes from tempest-react-sdk/vite, not the main
barrel tempest-react-sdk.
import { createViteConfig } from "tempest-react-sdk/vite";
Why a separate subpath?
The main barrel runs in the browser (React components, hooks). But
createViteConfig runs in Node, inside vite.config.ts, during the
build. Different environments — so the helper lives in a dedicated subpath, to
never drag config code into your production bundle.
Peer deps
vite and @vitejs/plugin-react are optional peer dependencies of the SDK.
Since every Vite app already has both in its devDependencies, there's nothing
extra to install — the helper just reuses them.
Only createViteConfig needs @vitejs/plugin-react, and it only loads it when
the config is built. The other helpers of this subpath (tempestVitest,
tempestCsp, tempestStyles, …) work without it — in a library, or in an app on
@vitejs/plugin-react-swc. Up to 0.73.0, importing any of them required the
React plugin to be installed (ERR_MODULE_NOT_FOUND,
#401).
The minimal example
With no options at all, you still get the full defaults:
// vite.config.ts
import { createViteConfig } from "tempest-react-sdk/vite";
export default createViteConfig();
That gives you:
| Default | Value |
|---|---|
| React plugin | enabled |
tempestVitest() |
enabled |
@ alias |
→ src |
server.port |
5173 |
server.host |
"127.0.0.1" |
server.open |
false |
The @ alias (and the tsconfig that must follow)
The most useful default is the @ alias: it points at your source directory, so
@/components/Button resolves to <root>/src/components/Button. No more
../../../components/Button.
// src/main.tsx
import { Button } from "@/components/Button";
import { formatBRL } from "@/utils/money";
The source path is resolved against process.cwd() (the project root, where Vite
runs from). Want to alias a different folder? Use srcDir:
// vite.config.ts
import { createViteConfig } from "tempest-react-sdk/vite";
export default createViteConfig({
srcDir: "app", // now @ → <root>/app
});
The @ alias must ALSO live in tsconfig.json
Vite and TypeScript resolve paths independently. createViteConfig teaches
Vite to resolve @, but the type-checker knows nothing until you declare the
same alias in compilerOptions.paths. Without it, tsc complains "Cannot find
module '@/...'" even though the app runs fine.
// tsconfig.json — keep the @ alias in sync for the type-checker
{
"compilerOptions": {
"paths": { "@/*": ["./src/*"] }
}
}
If you change srcDir, change paths too (e.g. "@/*": ["./app/*"]).
Proxy: string shorthand vs. object
The proxy option accepts two shapes. String values are the common shorthand:
you pass just the target URL and the helper auto-expands it to
{ target, changeOrigin: true }.
// vite.config.ts
import { createViteConfig } from "tempest-react-sdk/vite";
export default createViteConfig({
proxy: { "/api": "http://127.0.0.1:8000" },
});
// becomes { "/api": { target: "http://127.0.0.1:8000", changeOrigin: true } }
Need fine control (path rewrite, websocket, headers)? Pass an object — it
passes through raw as Vite's ProxyOptions, with no magic:
// vite.config.ts
import { createViteConfig } from "tempest-react-sdk/vite";
export default createViteConfig({
proxy: {
"/api": "http://127.0.0.1:8000", // string shorthand
"/ws": {
target: "ws://127.0.0.1:8000", // raw object
ws: true,
changeOrigin: true,
},
},
});
Mix the two freely
Each proxy key is handled independently: strings are expanded, objects pass
through. Use the shorthand where you can and the object where you must.
The escape hatch: overrides
The defaults cover most apps, but no helper anticipates everything. The
overrides option takes an arbitrary Vite UserConfig and deep-merges it
last, after everything the helper built.
// vite.config.ts
import { createViteConfig } from "tempest-react-sdk/vite";
export default createViteConfig({
srcDir: "app",
port: 3000,
alias: { "~": "/lib" },
overrides: { build: { target: "es2020" } },
});
Merged, not replaced
In overrides, the keys plugins, resolve, and server are merged with
what the helper already configured — not overwritten. So an overrides.server
with a new key coexists with the port/host you passed as top-level options,
and overrides.plugins are appended to yours. The rest of the UserConfig
(build, define, etc.) applies normally.
Testing with Vitest
Every SDK component imports its own stylesheet. In the app, Vite resolves that
import. In a Vitest suite, it does not: Vitest hands every ESM package from
node_modules to Node, and Node cannot load .css. Any test that imports the
SDK dies before running:
TypeError: Unknown file extension ".css" for …/node_modules/tempest-react-sdk/dist/styles/component/Accordion.css
If your vite.config.ts is createViteConfig, there is nothing to do: it
already includes tempestVitest(), which tells Vitest to transform the SDK through
Vite's pipeline, as the app does. Outside Vitest the plugin is inert — Vite ignores
the test key.
With a vitest.config.ts of your own, add the plugin:
// vitest.config.ts
import { defineConfig } from "vitest/config";
import { tempestVitest } from "tempest-react-sdk/vite";
export default defineConfig({
plugins: [tempestVitest()],
test: { environment: "jsdom" },
});
Measured with tempest-react-sdk@0.70.0 and a one-line test importing Button
(the repro of #397):
| Vitest | default config | with tempestVitest() |
|---|---|---|
| 2.1.9 | ❌ Unknown file extension ".css" |
✅ 1 passed |
| 3.2.7 | ❌ Unknown file extension ".css" |
✅ 1 passed |
| 4.1.11 | ❌ Unknown file extension ".css" |
✅ 1 passed |
| 5.1.1 | ❌ Unknown file extension ".css" |
✅ 1 passed |
The 5.1.1 row was measured on 20/11/2026 with the 0.90.0 tarball, by
scripts/smoke-vitest.sh, which since then runs every scenario on Vitest 4 and 5.
What the plugin does underneath
It adds "tempest-react-sdk" to test.server.deps.inline, on top of whatever
list you already have. If your config already uses inline: true (inline
everything), the plugin leaves it alone — merging the two would crash Vitest 4
with ex.test is not a function.
On 0.81.0 with Vitest 4.1.12 the picture is the same for every setup without
the plugin: an own vitest.config.ts, a plain vite.config.ts and a project with
no config at all fail on the .css. Two things make sure you find out before the
red test:
npx tempest doctorreads the config Vitest is going to load (vitest.config.*, elsevite.config.*) and warns under Integration when it has none oftempestVitest(),createViteConfig,inline: trueor"tempest-react-sdk"in theinlinelist — or when there is no config at all. Avitest.config.tsthat doesmergeConfigover avite.config.tsbuilt withcreateViteConfigpasses.- The tarball smoke (
scripts/smoke-vitest.sh, inmake check) runs the consumer suite without the plugin and requires the error. If the SDK ever imports under Vitest unaided, the smoke fails and this section gets revisited.
PWA: the service worker in the production build
A PWA app uses two plugins from the same subpath: tempestPwaManifest() emits
the precache-manifest.json that installPrecache reads, and tempestPwaDevSw()
compiles your src/sw.ts. With both, vite build ships the worker too:
// vite.config.ts
import { createViteConfig, tempestPwaDevSw, tempestPwaManifest } from "tempest-react-sdk/vite";
export default createViteConfig({
plugins: [
tempestPwaManifest({ additionalUrls: ["/icon.svg"] }),
tempestPwaDevSw({ swSrc: "src/sw.ts", swUrl: "/sw.js" }),
],
});
What lands in dist/:
| File | Emitted by | What it is |
|---|---|---|
precache-manifest.json |
tempestPwaManifest() |
The build's asset list + version (a hash of the list) |
sw.js |
tempestPwaDevSw() |
src/sw.ts bundled as a classic (IIFE) worker, minified |
- In dev,
tempestPwaDevSw()serves/sw.jscompiled on the fly and an empty manifest. In the build, it bundles the sameswSrcwith Vite's ownbuild()— noesbuildinstall and no separatevite.sw.config.tsneeded. - The worker's
import.meta.envsees the sameVITE_*values as the page (the app'smode,envDirandenvPrefix). - The first line of
sw.jsis/* tempest-precache-version: <version> */. The browser only reinstalls a service worker when the bytes ofsw.jschange; without it, a deploy that touches the app but notsw.tswould leave the old precache serving the previous version offline.
The build fails instead of shipping a broken PWA
Up to 0.82.0 tempestPwaDevSw() only ran in dev, and an app with both plugins
finished vite build with exit code 0 without dist/sw.js (#573): in
production the registration 404'd, navigator.serviceWorker.ready never resolved
and push, updates and offline hung without a message. Three errors now fail the
build, with the fix in the message:
| Situation | Message starts with |
|---|---|
precache-manifest.json emitted and no file at /sw.js (or at swUrl) |
[tempest-pwa-manifest] the build emitted … |
swSrc does not exist or does not compile |
[tempest-pwa-dev-sw] could not bundle … |
An additionalUrls entry that is neither in public/ nor in the bundle |
[tempest-pwa-manifest] additionalUrls lists … |
The third catches the neighbouring trap: a manifest.webmanifest linked from
index.html but kept outside public/ is emitted hashed as
assets/manifest-*.webmanifest (and is precached on its own). Listing
/manifest.webmanifest in additionalUrls made the precache store the SPA
fallback index.html in its place. Absolute http(s): URLs are not checked.
Worker bundled by another step
If a second vite build --config vite.sw.config.ts (or vite-plugin-pwa)
produces sw.js after this build, say so explicitly: use
tempestPwaDevSw({ build: false }) (it still serves in dev) or, without the
dev plugin, tempestPwaManifest({ serviceWorker: false }). With
tempestPwaDevSw() building by default, a separate build:sw is redundant and
can leave package.json.
| Option | Default | What it does |
|---|---|---|
tempestPwaDevSw({ build }) |
true |
Bundles swSrc into the production build at swUrl |
tempestPwaManifest({ serviceWorker }) |
tempestPwaDevSw's swUrl, else /sw.js |
Worker URL required in the build; false turns it off |
ONNX models in the browser: tempestOrtAssets
ONNX Runtime Web (/speech, /tabular, /vision) does not embed its .wasm files, not even in the .bundle builds. In a bundled app the session fails with Aborted(both async and sync fetching of the wasm failed), naming no file. The plugin serves the binaries of the onnxruntime-web the app installed, from your own origin:
import { createViteConfig, tempestOrtAssets } from "tempest-react-sdk/vite";
export default createViteConfig({
plugins: [tempestOrtAssets({ crossOriginIsolation: true })],
});
With Vite's own defineConfig, the plugin goes into plugins the same way.
vite dev: answers/ort/<file>straight fromnode_modules/onnxruntime-web/dist/.- Build: emits the same four files (
ort-wasm-simd-threaded[.jsep].{wasm,mjs}) intodist/ort/. - Workers as ES modules (
worker.format: "es") unless the app already chose. Vite's default, IIFE, cannot code-split, and a model's worker always has the lazyimport("onnxruntime-web"): without this, the build fails withInvalid value "iife" for option "worker.format". crossOriginIsolation: true(defaultfalse): sendsCross-Origin-Opener-Policy: same-originandCross-Origin-Embedder-Policy: credentiallessfromvite devandvite preview. The page becomescrossOriginIsolatedand WASM runs on several threads, 2.3× faster on whisper-base.credentiallesskeeps cross-origin images and fonts loading (without cookies), whichrequire-corpwould block. In production your server sends the headers; see Threads.- Package not installed: fails at startup saying what to install. A version missing one of the files fails naming the file.
In production, the server must serve .mjs as JavaScript
ONNX Runtime loads ort-wasm-simd-threaded.jsep.mjs as a module, and nginx's default mime.types does not know .mjs: the file goes out as application/octet-stream, the browser refuses it (Failed to fetch dynamically imported module) and the model does not load. Found serving a real app through nginx. Add a location ~* \.mjs$ { types { } default_type application/javascript; }, or application/javascript mjs; to your mime.types.
Point the runtime at the same path, once at boot: configureOrtAssets("/ort/") (or ortAssetsUrl: "/ort/" on each model). The files (~25 MB) are not added to the PWA precache, so installs that never use the model do not pay for them. For offline inference from the first launch, pass ortAssetUrls("/ort/") to tempestPwaManifest's additionalUrls.
Options reference
All options are optional.
| Option | Type | Default | What it does |
|---|---|---|---|
srcDir |
string |
"src" |
Directory aliased to @, resolved against process.cwd(). |
port |
number |
5173 |
Dev-server port. |
host |
string \| boolean |
"127.0.0.1" |
Dev-server host. |
open |
boolean |
false |
Open the browser on dev start. |
proxy |
Record<string, string \| object> |
— | Dev proxy. Strings become { target, changeOrigin: true }; objects pass through raw. |
alias |
Record<string, string> |
— | Extra aliases merged on top of the default @. |
plugins |
unknown[] |
— | Vite plugins appended after the React plugin. |
overrides |
Record<string, unknown> |
— | Arbitrary UserConfig deep-merged last. |
Content-Security-Policy
tempestCsp() lives in the same subpath and derives connect-src from the
VITE_* variables the app reads at runtime. See Content-Security-Policy.
Theme without a flash
tempestThemeInit() lives here too: it injects themeInitScript() at the top of
<head>, and tempestCsp() allows it by hash. See
No-flash.
Recap
- Import
createViteConfigfromtempest-react-sdk/vite— the dedicated Node subpath, separate from the browser barrel. - Call and assign:
export default createViteConfig({ ... }). With no options you already get the React plugin, the@→srcalias, and a dev server on127.0.0.1:5173. - Also declare the
@alias intsconfig.json("paths": { "@/*": ["./src/*"] }) — Vite and TS resolve paths independently. - In
proxy, strings are shorthand ({ target, changeOrigin: true }); objects pass through raw asProxyOptions. - In a Vitest suite,
tempestVitest()(already included) lets the SDK import withoutUnknown file extension ".css"; with avitest.config.tsof your own, add it. overridesis the escape hatch: deep-merged last, mergingplugins/resolve/serverinstead of replacing them.- PWA:
tempestPwaManifest()+tempestPwaDevSw()shipdist/sw.jsinvite build, and the build fails when the manifest ships without a worker oradditionalUrlspoints at nothing.