package
Universal build plugin for FormatJS — supports Vite, Webpack, Rollup, esbuild, Rspack, and Rsbuild
npm install @formatjs/unpluginGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Universal build plugin for FormatJS AST transformations. Supports Vite, Webpack, Rollup, esbuild, Rspack, and Rsbuild with one codebase.
Replicates the functionality of babel-plugin-formatjs and @formatjs/ts-transformer using oxc-parser + magic-string for fast, compiler-agnostic builds.
npm install @formatjs/unplugin --save-dev// vite.config.ts
import {defineConfig} from 'vite'
import formatjs from '@formatjs/unplugin/vite'
export default defineConfig({
plugins: [
formatjs({
idInterpolationPattern: '[sha512:contenthash:base64:6]',
ast: true,
}),
],
})// webpack.config.js
const formatjs = require('@formatjs/unplugin/webpack').default
module.exports = {
plugins: [
formatjs({
idInterpolationPattern: '[sha512:contenthash:base64:6]',
ast: true,
}),
],
}// rollup.config.js
import formatjs from '@formatjs/unplugin/rollup'
export default {
plugins: [
formatjs({
idInterpolationPattern: '[sha512:contenthash:base64:6]',
ast: true,
}),
],
}import esbuild from 'esbuild'
import formatjs from '@formatjs/unplugin/esbuild'
esbuild.build({
plugins: [
formatjs({
idInterpolationPattern: '[sha512:contenthash:base64:6]',
ast: true,
}),
],
})// rspack.config.js
const formatjs = require('@formatjs/unplugin/rspack').default
module.exports = {
plugins: [
formatjs({
idInterpolationPattern: '[sha512:contenthash:base64:6]',
ast: true,
}),
],
}// rsbuild.config.ts
import {defineConfig} from '@rsbuild/core'
import formatjs from '@formatjs/unplugin/rsbuild'
export default defineConfig({
plugins: [
formatjs({
idInterpolationPattern: '[sha512:contenthash:base64:6]',
ast: true,
}),
],
})Message fields can reference local const strings, including aliases, templates,
string concatenations, and constant conditionals. OXC performs native scope analysis and static evaluation through
@formatjs/cli-lib. Constants must be initialized before the reference. Lexical scope
and shadowing are respected for JSX and message descriptors.
function Greeting() {
const greeting = 'Hello'
return <FormattedMessage defaultMessage={greeting} />
}Imported values, mutable bindings, destructured bindings, and runtime expressions remain unresolved. Keep those message fields inline when they need generated IDs or precompiled ASTs.
Native expression evaluation supports macOS arm64, Linux x64/arm64 (glibc and musl), and Windows x64.
| Option | Type | Default | Description |
|---|---|---|---|
idInterpolationPattern | string | [sha512:contenthash:base64:6] | Pattern for generating message IDs |
overrideIdFn | function | — | Custom function to generate message IDs |
removeDefaultMessage | boolean | false | Remove defaultMessage from output |
additionalComponentNames | string[] | [] | Extra JSX component names to process |
additionalFunctionNames | string[] |
filter is forwarded to unplugin's transform.filter hook. Passing a custom filter replaces the default module policy, which matches JavaScript and TypeScript module IDs outside node_modules.
import formatjs from '@formatjs/unplugin/vite'
formatjs({
filter: {
id: /^(?!.*\/node_modules\/).*\.tsx?$|\/node_modules\/@my-org\/learning-block\/.*\.tsx?$/,
code: /FormattedMessage|defineMessages?|formatMessage|defaultMessage/,
},
})redonkulus
seth@bertalotto.net
[]| Extra function names to process |
ast | boolean | false | Pre-parse defaultMessage into AST |
preserveWhitespace | boolean | false | Keep original whitespace in messages |
filter | HookFilter | JS/TS outside node_modules | Filter modules before transformation |
Estimated unpacked size across 65 packages.
464.4 MB+
Includes dependencies.
9 direct dependencies.
>=3.4.0
3.7.0
0.158.0
22 || 24 || 26
26.6.6
1.4.5
6.5.0
10.3.0
10.3.0
4.5.3
3.5.23
3.5.23