SayKit
Integrations

Babel

Use SayKit with Babel for Next.js, React Native, Metro, Expo, or any Babel-driven pipeline

babel-plugin-saykit is for builds that run Babel: Next.js, React Native, Expo, or your own setup. Not pinned to Babel? Use unplugin-saykit.

Install

pnpm add -D babel-plugin-saykit @saykit/config @saykit/format-po @saykit/transform-js @saykit/transform-jsx

Use

Next.js

.babelrc
{
  "presets": ["next/babel"],
  "plugins": ["saykit"]
}
next.config.mjs
import { withSayKit } from 'babel-plugin-saykit/next';

export default withSayKit({});

Adding a .babelrc switches Next.js from SWC to Babel. There is no SWC plugin, so this is how SayKit runs in Next.js. withSayKit compiles the catalogues; see what it does.

Expo

babel.config.js
module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: ['saykit'],
  };
};
metro.config.js
const { getDefaultConfig } = require('expo/metro-config');
const { withSayKit } = require('babel-plugin-saykit/metro');

module.exports = withSayKit(getDefaultConfig(__dirname));

Bare React Native is the same with module:metro-react-native-babel-preset and @react-native/metro-config.

Plain Babel

babel.config.js
export default {
  plugins: ['saykit'],
};

Plain Babel has no dev server or config to hook into, so compile the catalogues yourself before building:

package.json
{
  "scripts": {
    "prebuild": "saykit compile"
  }
}

What it does

The plugin rewrites macros to say.call(...) in every source file outside node_modules.

withSayKit compiles each catalogue into an ordinary {locale}.js module when Next.js or Metro evaluates its config, before anything is bundled. Under next dev and expo start it then watches the catalogues and recompiles on every change, so editing en.po rewrites every locale that falls back to it, and the bundler hot-reloads those modules like any other. next start compiles nothing, so a deployment that only serves a build needs neither saykit.config.* nor its formatters. The Next.js wrapper returns a config function, so keep it outermost when combining it with wrappers that expect a config object; the Metro wrapper returns your config untouched.

A write is skipped when a module would not change, and Next.js's worker processes leave compiling to the process that started them, so nothing reloads for no reason.

Keep saykit extract --watch running in development so the source catalogue follows your code.

Next

On this page