babel-plugin-kea
raw JSON → 3.0.0 verified Sat Apr 25 auth: no javascript
A Babel plugin that automatically generates path strings for Kea logic stores based on the file path. Version 3.0.0 is the latest stable release. It eliminates the need to manually specify a `path` property in every `kea()` call, with support for dynamic keys and custom path prefix configuration. Unlike manual path management, this plugin ensures consistency and reduces boilerplate in Kea-based projects. It requires Kea 3.x and is intended for build-time usage with Babel.
Common errors
error Error: Could not find plugin "babel-plugin-kea" ↓
cause Plugin not installed or not in node_modules.
fix
Run 'npm install babel-plugin-kea --save-dev' or 'yarn add babel-plugin-kea --dev'.
error TypeError: babelPluginKea is not a function ↓
cause Incorrect import/require when using programmatic API (e.g., require('babel-plugin-kea').default).
fix
Use 'const plugin = require('babel-plugin-kea')' (no .default).
error Error: Plugin options must be an array when using two-element tuple ↓
cause Misconfigured .babelrc plugins array (e.g., missing nested array).
fix
Use [['babel-plugin-kea', { path: './src' }]] not ['babel-plugin-kea', { path: './src' }].
Warnings
breaking Plugin v3.x only works with Kea 3.x. Using with Kea 2.x will break. ↓
fix Upgrade Kea to 3.x or use babel-plugin-kea@2.x for Kea 2.x.
gotcha If a kea({ path: ... }) already has a path string, the plugin will NOT override it. It only adds path when missing. ↓
fix Remove explicit path from kea() calls to let plugin generate them automatically.
gotcha The generated path uses the file path relative to the project, not the module name. Moving files changes the path. ↓
fix Use the 'path' option to trim a prefix (e.g., './src') to keep paths stable if files move under src.
deprecated Plugin auto-generates path based on file path. To override path for a specific logic, you must still provide a custom path function; an array or string will be treated as custom path and not overwritten. ↓
fix Use path: () => [...] for dynamic paths; static paths as arrays are not modified.
Install
npm install babel-plugin-kea yarn add babel-plugin-kea pnpm add babel-plugin-kea Imports
- plugin (default) wrong
plugins: ['babel-plugin-kea', { path: './src' }] (wrong syntax, must be nested array)correctplugins: ['babel-plugin-kea'] - Plugin with options wrong
plugins: ['babel-plugin-kea', { path: './src' }] (options must be inside nested array)correctplugins: [['babel-plugin-kea', { path: './src' }]] - Programmatic usage wrong
const plugin = require('babel-plugin-kea').default (default export is the plugin function)correctconst plugin = require('babel-plugin-kea'); require('@babel/core').transform(code, { plugins: [plugin] })
Quickstart
// .babelrc
{
"plugins": [
"babel-plugin-kea"
]
}
// With path prefix to skip 'frontend/src':
// {
// "plugins": [
// ["babel-plugin-kea", { "path": "./frontend/src" }]
// ]
// }