formatjs / babel-plugin-react-intl

Extracts string messages from React components that use React Intl.
http://formatjs.io/react/
Other
420 stars 122 forks source link

Plugin does nothing, how to debug? (using with Gatsby) #169

Closed onokje closed 5 years ago

onokje commented 5 years ago

I have a Gatsby site that i want to use this plugin with. I installed it and added the .babelrc, but nothing happens when i do a build (I mean the build works fine, but nothing is written in ./build). It has probably something to do with the fact that i am using a gatsby site.

My .babelrc file looks like this: { "presets": [ [ "babel-preset-gatsby" ] ], "plugins": [ ["react-intl", { "messagesDir": "./build/messages/" }] ] }

I would like to know how i can debug this.

slorber commented 5 years ago

This plugin can work with Gatsby.

But Gatsby don't use .babelrc, you have to register the plugin with their own api:

exports.onCreateBabelConfig = ({ actions }) => {
  actions.setBabelPlugin({
    name: `babel-plugin-react-intl`,
    options: {
      // enforceDescriptions: true, // TODO re-enable this later
      messagesDir: './translations/extracted',
    },
  });
};

You can also look at this: https://github.com/yahoo/babel-plugin-react-intl/issues/168#issuecomment-490041032

longlho commented 5 years ago

Seems like this has been resolved.