1

I have /components/foo.js and /pages/bar.js, both are using <FormattedMessage /> with a different defaultMessage:

// /components/foo.js
export default function Foo() {
  return (
    <FormattedMessage defaultMessage="Foo component" />
  );
}

// /pages/bar.js
export default function Foo() {
  return (
    <FormattedMessage defaultMessage="Bar page" />
  );
}

If I run formatjs extract 'components/**/*.js' --out-file lang/en.json I only get messages from my components folder. If instead I use the path pages/**/*.js, I only get messages from my pages folder.

Tried a few differente combinations without luck:

  • (components,pages)/**/*.js
  • (components&pages)/**/*.js
  • (components|pages)/**/*.js
  • !(node_modules)/**/*.js to compile everything except the node_modules folder.
Camilo
  • 6,504
  • 4
  • 39
  • 60

3 Answers3

1

It turns out that you need to use double pipe operator ||.

formatjs extract '(components||pages)/**/*.js' --out-file lang/en.json
Camilo
  • 6,504
  • 4
  • 39
  • 60
1

We use https://www.npmjs.com/package/glob so {components,pages}/**/*.js should work

Long Ho
  • 599
  • 4
  • 15
1

Tried all the solutions mentioned above but what actually worked for us was formatjs extract 'components//*.js' 'pages//*.js' --out-file lang/en.json