A Rollup and Vite plugin that applies formatjs (react-intl) message extraction and translation transforms during the build process. Version 3.0.0 is the latest stable release, with monthly updates. It seamlessly integrates with the formatjs ecosystem, supporting both Rollup (^3) and Vite via plugin-compat. Unlike manual extraction, this automates the pipeline from source code to compiled messages, reducing configuration overhead. Ships TypeScript definitions.
npm install rollup-plugin-formatjsVerified import paths — ran on the pinned version, not inferred.
Basic Rollup config that applies formatjs transforms to source files, generating compiled message IDs and optimizations.
Upgrade Rollup to ^3.0.0.
Use default import: import formatjs from 'rollup-plugin-formatjs'
Set extractFromFormatMessageCall: true in plugin options.
Validate messages with @formatjs/cli extract command before building.
Use @ts-ignore or import via explicit path to types: import type { FormatjsOptions } from 'rollup-plugin-formatjs/lib/types'Switch to ESM imports (import formatjs from 'rollup-plugin-formatjs') or rename config to .mjs.
Use import formatjs from 'rollup-plugin-formatjs' instead of import { formatjs } from 'rollup-plugin-formatjs'.Run npm install or explicitly add @formatjs/icu-messageformat-parser to your dependencies.
Ensure formatjs plugin comes after CSS plugins or is configured only for JS files with include/exclude.