Bundler setup
The kit source-ships: main points at ./src/index.ts, not a built bundle.
That is deliberate — it keeps platform-split files (.native.tsx, .web.tsx)
resolvable by your bundler, and it means the Tamagui compiler can see real source
and flatten it. The cost is that your bundler has to be told about it, which is
what @knitui/plugins does.
Every entry point comes pre-wired with the kit's config and component list baked in, so you never reference a Tamagui package yourself.
Metro — @knitui/plugins/metro
const { getDefaultConfig } = require("expo/metro-config");
const { withKnitui } = require("@knitui/plugins/metro");
module.exports = withKnitui(getDefaultConfig(__dirname));Wraps Tamagui v3's Metro compiler (@tamagui/cli/metro). On v3 this is the
native compiler: it hoists static layout and colours out of render, and adds the
source extensions and resolver rules the kit's packages need. Pass compiler
options as the second argument: withKnitui(config, { disableExtraction: true }).
Babel — no plugin on v3
Tamagui v3 has no babel plugin, so babel.config.js stays on the stock preset
(babel-preset-expo or @react-native/babel-preset). @knitui/plugins/babel-plugin
still exists so an old config keeps building, but it is a deprecated no-op
that prints a one-time warning — remove it and use the Metro wrapper above. Set
KNITUI_SILENCE_BABEL_PLUGIN_WARNING=1 to mute it while you migrate.
Next.js — @knitui/plugins/next-plugin
import { withKnitui } from "@knitui/plugins/next-plugin";
export default withKnitui({
transpilePackages: ["react-native-web", "react-native-reanimated", "@knitui/components"],
});This one does the most work:
- runs the Tamagui compiler, flattening
styled()components to atomic CSS; - aliases
react-native→react-native-web, and orders resolution so.web.*files win; - aliases
react-native/Libraries/Image/AssetRegistryto RNW's equivalent, which Skia's web build reaches for directly; - stubs
fs/pathin the browser bundle forcanvaskit-wasm; - defines
globalasglobalThisin the client bundle — reanimated's web build touchesglobalat module scope, and the browser has none; - sets
optimizePackageImportsfor the barrel-shaped packages.
Vite — @knitui/plugins/vite
import { knitui } from "@knitui/plugins/vite";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [react(), knitui()] });Wraps @tamagui/cli/vite's tamaguiPlugin. It is ESM-only and has a Vite 8 peer.
In development it re-evaluates the config on save, so there is nothing to
regenerate by hand. TAMAGUI_COMPILER_STATS=verbose prints what the compiler
flattened and why it bailed.
Webpack — @knitui/plugins/webpack
For a non-Next webpack setup, the same resolution rules and compiler are available directly:
const TamaguiPlugin = require("@knitui/plugins/webpack");
config.plugins.push(TamaguiPlugin()); // or TamaguiPlugin({ disableExtraction: true })Extraction, and what it can and cannot flatten
The Tamagui compiler flattens styled() components into atomic CSS (web) or
hoisted styles (native) at build time. Behaviour components — every kit component
built with styleable() from @knitui/core (v3's createStyledHOC) — are always
neverFlatten: the component keeps its runtime wrapper so state, refs,
composition and slot styling keep working.
The practical consequence: expect the web output to carry react-native-web's
shape rather than fully static markup. It is a deliberate trade — composability
over maximal flattening — and it is why the docs set a JS budget per route rather
than assuming zero-runtime CSS. Plain styled(Box) frames with static variants
and styled.dynamic variants do flatten; see styled().
Checking the config — tamagui check
The Tamagui CLI (@tamagui/cli, which @knitui/plugins already brings in) can
validate your source against the config: unknown tokens, malformed flat values and
leftover v2 props. Point it at the kit's config with a tamagui.build.ts — v3's
loader defaults to the tamagui package, which the kit does not use, so both keys
must be explicit:
export default {
config: "@knitui/core/config",
components: ["@knitui/core", "@knitui/components"],
};npx tamagui generate && npx tamagui check