Babel / Next.js
Use the Babel plugin when your build pipeline cannot use the Vite plugin. The
Babel plugin is the underlying transform used by @usels/vite-plugin.
Install
Section titled “Install”npm add -D @usels/babel-plugin @babel/coreyarn add -D @usels/babel-plugin @babel/corepnpm add -D @usels/babel-plugin @babel/corebun add -D @usels/babel-plugin @babel/coreBasic Babel Configuration
Section titled “Basic Babel Configuration”module.exports = { plugins: ["@usels/babel-plugin"],};Next.js
Section titled “Next.js”For Next.js, add the plugin to .babelrc after the Next preset:
{ "presets": ["next/babel"], "plugins": [ [ "@usels/babel-plugin", { "autoWrap": { "importSource": "@usels/core" }, "autoScope": { "importSource": "@usels/core" } } ] ]}What It Does
Section titled “What It Does”The plugin handles the same two transforms as the Vite plugin:
| Transform | Effect |
|---|---|
autoWrap | Wraps JSX observable .get() reads with Memo boundaries |
autoScope | Transforms "use scope" into useScope(...) |
Use only one transform path for a file. If Vite is already running
@usels/vite-plugin, do not add the Babel plugin again for the same source.
- Ensure the transform runs before final JSX compilation.
- Keep
importSourceas@usels/coreunless you intentionally provide a custom reactive wrapper. - Prefer Vite when your app uses Vite.