Run react-intl at build-time with babel-plugin-macros. Current stable version is 0.3.7 (last released Feb 2020; no recent updates, likely maintenance mode). It extracts react-intl defineMessages, FormattedMessage, and FormattedHTMLMessage calls into JSON files during build, leveraging babel-plugin-macros without needing a separate Babel plugin. Different from babel-plugin-react-intl (requires explicit Babel config) and react-intl-cra (Create React App specific) – this macro approach works with any macro-enabled setup (CRA, Next.js, custom builds). Requires react-intl@2 and babel-plugin-macros.
npm install react-intl.macroVerified import paths — ran on the pinned version, not inferred.
Shows installation, config, and usage of react-intl.macro to replace react-intl imports and extract messages during build.
Use react-intl v2.x or consider alternative extraction tools for modern react-intl.
Set MESSAGE_DIR to a directory path, e.g., MESSAGE_DIR='./.messages' react-scripts build
Consider using babel-plugin-react-intl (v9+) or @formatjs/cli for extraction in modern projects.
Keep injectIntl and other non-extracted imports from 'react-intl'; only replace extraction-targets with react-intl.macro.
Install react-intl.macro and babel-plugin-macros; ensure Babel config includes 'macros' plugin.
Run 'yarn add babel-plugin-macros' and add 'macros' to your Babel plugins in babel.config.js.
Set MESSAGE_DIR environment variable (e.g., MESSAGE_DIR='./.messages') and ensure imports come from 'react-intl.macro', not 'react-intl'.