Configuration and Codegen
gtkx.config.ts identifies your application and selects the libraries GTKX generates bindings for. GTKX 2 includes Adwaita and GTK by default. For resource imports, see Assets; for native type wrappers, see Calling Native APIs.
The config file
Create gtkx.config.ts in the project root:
import { defineConfig } from "@gtkx/config";
export default defineConfig({
applicationId: "com.example.Tasks",
});List additional libraries by GIR name and version, for example libraries: ["WebKit-6.0"]. Codegen starts from Adw-1 and follows its GIR dependencies, including Gtk-4.0. Omit these two entries from libraries; listing them explicitly is an error.
defineConfig provides editor completion. An application's ID uses a reverse-DNS name such as com.example.Tasks; gtkx dev, gtkx build and gtkx deploy stop when it is missing. Only a package that is not an application, such as a component library, leaves it out.
Configuration modules and their local imports use ESM. Use .ts, .mts, .js, or .mjs files with import and export; TypeScript configuration runs through Node's native type stripping and must use erasable syntax. JSON, JSONC, JSON5, YAML, and TOML configuration files are also supported.
gtkx dev watches the config and the local dependencies it loads, including shared config layers and imported data, and the GIR files the bindings were generated from, such as a library built alongside the app into a girPath directory. Changes regenerate bindings and restart the app.
Install the corresponding GIR files before generating bindings. Use girPath when they live outside the standard search directories; relative paths start at the project root. Supplying a newer GIR file changes the declarations, not the library that runs your app.
At run time the dynamic linker loads each library by the shared-library name its GIR file records, so a library built alongside the app has to be installed or on the linker's search path. Point LD_LIBRARY_PATH at its build directory for gtkx dev, gtkx build output and Vitest, as meson devenv does; a library the linker cannot find fails with the linker's reason, such as cannot open shared object file.
Use the configuration reference for available settings. The React Compiler is enabled by default; reactCompiler: false disables it. Application icons and package metadata are covered in Deploying, and agent tool settings in MCP.
Modes and shared configuration
$development and $production blocks override settings in one mode. gtkx dev runs in development mode; gtkx build and gtkx deploy run in production mode:
export default defineConfig({
applicationId: "com.example.Tasks",
$development: { applicationId: "com.example.Tasks.Devel" },
});The app reads the resolved application ID from virtual:gtkx-config, a module GTKX generates from the config file. Under gtkx dev it holds the $development value. The scaffold's src/gtkx-env.d.ts types the module:
import { applicationId } from "virtual:gtkx-config";For shared configuration, mergeConfig(base, override) applies the override over the base; arrays concatenate with override entries first.
To pick another configuration file for one command or for tests, pass --config.
Environment files
gtkx dev, gtkx build and Vitest read Vite's environment files from the project directory: .env, .env.local, .env.[mode] and .env.[mode].local, where the mode is development for gtkx dev, production for gtkx build and test for Vitest. Variables whose names start with VITE_ appear on import.meta.env; the others stay out of the app.
VITE_REPORT_URL=https://reports.example.com/submitconst endpoint = import.meta.env.VITE_REPORT_URL;The scaffold's src/gtkx-env.d.ts types import.meta.env, including MODE, DEV and PROD. Declare your own variables there:
interface ImportMetaEnv {
readonly VITE_REPORT_URL: string;
}Only the project directory is read. A .env at the root of a workspace does not apply to the apps in it, and no setting moves the directory; keep each app's files next to its gtkx.config.ts.
gtkx build writes each value into dist/bundle.mjs as text, so it ships in every package gtkx deploy makes and cannot be changed on an installed app. Never put secrets in these files: anyone with the package can read them. Read settings that differ per machine or per run from process.env when the app runs.
Future flags
The future block opts into behavior that becomes the default in the next major version, so you can move to it one change at a time. Every flag is off by default.
export default defineConfig({
applicationId: "com.example.Tasks",
future: { v3ControlledRestore: true },
});v3ControlledRestore: keeps props that hold state the user edits at the value the app renders, as React DOM does for a controlled input. See Controlled Props.
Generated bindings
Run generation after installing dependencies or changing the configured libraries:
gtkx codegenGTKX generates modules under node_modules/.gtkx and links them as @gtkx/gi and @gtkx/jsx. They belong to the project and are not separate npm dependencies. gtkx dev, gtkx build and the Vitest plugin also generate them when they are missing or out of date.
A project without @gtkx/react gets only @gtkx/gi, and its @gtkx/jsx comes back once @gtkx/react is installed again. Projects that resolve the same dependency directory share their generated bindings, as described in Shared bindings.
Import classes, enums, and functions from GI modules, and elements from JSX modules:
import * as Gtk from "@gtkx/gi/gtk";
import { AdwHeaderBar } from "@gtkx/jsx/adw";
import { GtkBox, GtkButton } from "@gtkx/jsx/gtk";Both packages use namespace subpaths; neither has a bare root import. Use @gtkx/cairo for Cairo.
Importing a namespace initializes its library: when its GIR declares a top-level init function that takes no arguments, such as Gtk.init() or Gst.init(), the namespace calls it as it loads, so a later Gst.init(argv) call does nothing and GStreamer options go through environment variables such as GST_DEBUG. Library teardown functions such as GtkSource.finalize() are never called; the process releases the libraries when it exits.
A production build keeps only the generated classes the app references; Troubleshooting covers the errors this causes.
Workspaces covers monorepos and component libraries. JSX Elements covers the prop model, member names, element reference docs and custom props, Calling Native APIs covers GTypes and GValues, and App Inspection (MCP) covers the files codegen writes for coding agents.