How do you make relay-compiler run automatically?

Making relay-compiler run automatically

Relay can be annoying to work with as relay-compiler needs to run every time you change your GraphQL schema, or your resolvers.

With relay-compiler-webpack-plugin that's no longer the case - webpack can run it for you!

Here's how you use it:

const RelayCompilerWebpackPlugin = require('relay-compiler-webpack-plugin');
// rest of your config
new RelayCompilerWebpackPlugin({
    schema: 'schema.graphql',
    src: 'src/',
    extensions: ['js', 'jsx', 'ts', 'tsx'],
    artifactDirectory: 'src/__generated__',
}),

Enjoyed this post? Receive the next one in your inbox!