Skip to content
Advertisement

How do I extract messages from multiple specific folders with FormatJS CLI?

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.

Advertisement

Answer

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

formatjs extract '(components||pages)/**/*.js' --out-file lang/en.json
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement