Knit UI
GitHub

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

metro.config.js
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

next.config.mjs
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/AssetRegistry to RNW's equivalent, which Skia's web build reaches for directly;
  • stubs fs/path in the browser bundle for canvaskit-wasm;
  • defines global as globalThis in the client bundle — reanimated's web build touches global at module scope, and the browser has none;
  • sets optimizePackageImports for the barrel-shaped packages.

Vite — @knitui/plugins/vite

vite.config.ts
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:

webpack.config.js
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:

tamagui.build.ts
export default {
  config: "@knitui/core/config",
  components: ["@knitui/core", "@knitui/components"],
};
npx tamagui generate && npx tamagui check

Edit this page on GitHub