unplugin-saykit package provides a universal plugin that works across multiple build tools, transforming Saykit messages at build time without requiring Babel.
Installation
Supported Bundlers
The unplugin works with:- Vite (recommended for modern projects)
- webpack 4, 5
- Rollup 2, 3, 4
- esbuild
- Rspack
- Farm
- Rolldown
Basic Usage
Vite
vite.config.ts
webpack
webpack.config.js
webpack.config.ts
Rollup
rollup.config.js
esbuild
build.js
Rspack
rspack.config.ts
Farm
farm.config.ts
Configuration Options
The plugin accepts an optional configuration object:- Excludes
node_modulesfrom processing - Processes supported file extensions (
.js,.jsx,.ts,.tsx,.mjs,.cjs,.mts,.cts) - Uses the Saykit Babel transformer under the hood
How It Works
Code Transformation
For each eligible file, it uses
@saykit/babel-plugin/core to transform the code:Framework Examples
Next.js with SWC
Next.js 13+ uses SWC by default, which doesn’t support Babel plugins. Use the webpack plugin:next.config.js
Vite + React
vite.config.ts
Vite + Vue
vite.config.ts
SvelteKit
vite.config.ts
Remix with Vite
vite.config.ts
Astro
astro.config.mjs
Transformations
The unplugin applies the same transformations as the Babel plugin. See the Babel Plugin documentation for detailed transformation examples.Quick Reference
- JSX
- Plural
- Ordinal
- Select
Performance
Build Time
The unplugin adds minimal overhead to your build:- Files in
node_modulesare automatically skipped - Only files with Saykit usage are transformed
- Transformations are cached by the build tool
Development Experience
- Vite
- webpack
- esbuild
- Fast Hot Module Replacement (HMR)
- Minimal impact on dev server startup
- Only transforms changed files
Debugging
Enable Verbose Logging
Check your build tool’s output for transformation information:Verify Plugin Loading
Ensure the plugin is loaded by checking your build configuration:Check Transformations
Inspect the build output to verify transformations were applied:Comparison: Babel Plugin vs Unplugin
- Babel Plugin
- Unplugin
Pros:
- Deep Babel integration
- Works with all Babel-based tools
- Highly configurable
- Requires Babel in your build pipeline
- Slower than modern alternatives
- Not compatible with SWC or esbuild-only setups
- Projects already using Babel
- Next.js with Babel
- Create React App (ejected)
Troubleshooting
Plugin not transforming files
- Verify the plugin is in your build configuration
- Check that you’re importing from the correct path (e.g.,
unplugin-saykit/vite) - Ensure files aren’t in
node_modules
TypeScript errors
Make sure you have the necessary type definitions:Build errors
If you see transformation errors:- Check that your syntax is valid JSX/TSX
- Ensure
Sayis imported from@saykit/react - Verify file extensions are supported
Hot reload issues (Vite)
If changes aren’t reflected:- Restart the dev server
- Clear Vite cache:
rm -rf node_modules/.vite - Check browser console for errors
Migration from Babel Plugin
If you’re migrating from@saykit/babel-plugin:
Hash IDs are generated the same way in both plugins, so your message catalogs remain compatible.
See Also
- React Integration - Using the Say component
- Babel Plugin - Alternative for Babel-based builds
- Message Extraction - Understanding transformations