@palamedes/next-plugin
v0.1.1
Published
Next.js integration for Lingui using OXC-based macro transformer
Downloads
181
Maintainers
Readme
@palamedes/next-plugin
Next.js integration for Lingui using OXC-based macro transformation. No Babel required.
Features
- 🚀 Fast: Uses oxc-parser for high-performance parsing
- 🔧 No Babel: Transforms Lingui macros without Babel or SWC plugins
- 📦 PO Loader: Compiles
.pofiles to JS at build time - ⚡ Webpack & Turbopack: Works with both bundlers
Installation
pnpm add @palamedes/next-plugin @lingui/core @lingui/reactUsage
// next.config.js
const { withPalamedes } = require("@palamedes/next-plugin")
/** @type {import('next').NextConfig} */
const nextConfig = {
// your existing config
}
module.exports = withPalamedes(nextConfig)That's it! The plugin will:
- Transform Lingui macros (
t`...`,<Trans>, etc.) to runtime calls - Compile
.pofiles when imported
Options
const { withPalamedes } = require("@palamedes/next-plugin")
module.exports = withPalamedes(nextConfig, {
// Only transform files matching this pattern (optional)
include: /\.(tsx?|jsx?)$/,
// Exclude files matching this pattern (optional)
exclude: /node_modules/,
// Enable/disable .po file compilation (default: true)
enablePoLoader: true,
// Path to lingui.config.js (optional)
configPath: "./lingui.config.js",
// Fail build on missing translations (default: false)
failOnMissing: false,
// Fail build on compilation errors (default: false)
failOnCompileError: false,
// Module to import getI18n from (default: "@palamedes/runtime")
runtimeModule: "@palamedes/runtime",
})How It Works
With Webpack
The plugin adds webpack loaders that:
- Transform Lingui macros in JS/TS files before SWC processes them
- Compile
.pofiles to JS modules
With Turbopack
The plugin configures Turbopack rules to:
- Run the OXC transform loader for JS/TS files
- Compile
.pofiles to JS modules
Usage in Components
// Using macros (transformed at build time)
import { t } from "@lingui/macro"
import { Trans } from "@lingui/react/macro"
function Greeting({ name }) {
return (
<div>
<p>{t`Hello, ${name}!`}</p>
<Trans>Welcome to our app</Trans>
</div>
)
}// Importing .po files
import { getI18n } from "@palamedes/runtime"
import messages from "./locales/en.po"
const i18n = getI18n()
i18n.load("en", messages)
i18n.activate("en")Comparison with @lingui/swc-plugin
| Feature | @lingui/swc-plugin | @palamedes/next-plugin | |---------|-------------------|-------------------------| | PO compilation | ❌ (separate loader) | ✅ Built-in | | Macro transformation | ✅ | ✅ | | Written in | Rust | TypeScript | | Parser | SWC | OXC | | Easy to extend | Difficult | Easy |
License
MIT
