relay-compiler-webpack-plugin
Automatically run the Relay Compiler from Webpack
Last updated 10 days ago by dhau .
BSD-3-Clause · Repository · Original npm · Tarball · package.json
$ cnpm install relay-compiler-webpack-plugin 
SYNC missed versions from official npm registry.

Relay Compiler Webpack Plugin

npm version Build Status

Are you running Relay Modern? Are you annoyed with constantly running the relay-compiler to generate code, especially if you're already running Webpack?

Well be annoyed no more! Simply install this plugin to automatically hook into Webpack's build process to generate these files for you.

Installation

  1. Add this to your project:
  yarn add --dev relay-compiler-webpack-plugin
  # Or if you're using npm
  npm install --save-dev relay-compiler-webpack-plugin
  1. Add the plugin to your Webpack configuration:
const RelayCompilerWebpackPlugin = require('relay-compiler-webpack-plugin')
const path = require('path')

module.exports = {
  // ... Your existing Webpack configuration
  plugins: [
    // ...
    new RelayCompilerWebpackPlugin({
      schema: path.resolve(__dirname, './relative/path/to/schema.graphql'), // or schema.json
      src: path.resolve(__dirname, './relative/path/to/source/files'),
    })
  ]
  // ...
}
  1. :tada:

Gotchas

If there are multiple versions of GraphQL in your dependency tree it will cause schema validation errors. To get around this, ensure you have the same graphql version as your relay-compiler version depends on. To assist this you can install dependencies as flat which ensures only one version of each dependency.

Plugin hooks

relay-compiler-webpack-plugin exposes a few tapable hooks, for plugins or tooling to use.

  • beforeWrite called before the plugin starts to compile queries
  • afterWrite(compileResult): called after writing is complete
class MyPlugin {
  apply (compiler) {
    compiler.hooks.compilation.tap('MyPlugin', async (compilation) => {
      RelayCompilerWebpackPlugin.getHooks(compilation).afterWrite.tapPromise(
        'MyPlugin', // <-- Set a meaningful name for stacktraces
        async (compileResult) => {
          if (compileResult === 'HAS_CHANGES') {
            await doSomething()
          }
        }
      )
    })
  }
}

Example Project

To see an example of its usage within a project, see relay-compiler-webpack-plugin-example.

Development

Running tests:

yarn test

Running tests with coverage:

yarn test:coverage

License

Relay Compiler Webpack Plugin may be redistributed according to the BSD 3-Clause License.

Copyright 2019

Current Tags

  • 2.0.0-rc.5                                ...           dev (a year ago)
  • 8.1.0                                ...           latest (10 days ago)

49 Versions

  • 8.1.0                                ...           10 days ago
  • 8.0.2                                ...           5 months ago
  • 8.0.1                                ...           5 months ago
  • 8.0.0                                ...           5 months ago
  • 7.0.0                                ...           7 months ago
  • 6.2.0                                ...           7 months ago
  • 6.1.0                                ...           8 months ago
  • 6.0.0                                ...           9 months ago
  • 5.1.1                                ...           10 months ago
  • 5.1.0                                ...           10 months ago
  • 5.0.1                                ...           a year ago
  • 5.0.0                                ...           a year ago
  • 4.0.2                                ...           a year ago
  • 4.0.1                                ...           a year ago
  • 4.0.0                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 2.0.0-rc.5                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 2.0.0-rc.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 2.0.0-rc.2                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 2.0.0-rc.1                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.11.0                                ...           2 years ago
  • 0.10.0                                ...           2 years ago
  • 0.9.3                                ...           2 years ago
  • 0.9.2                                ...           2 years ago
  • 0.9.1                                ...           2 years ago
  • 0.9.0                                ...           2 years ago
  • 0.8.0                                ...           2 years ago
  • 0.7.0                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.11                                ...           2 years ago
  • 0.5.10                                ...           2 years ago
  • 0.5.9                                ...           3 years ago
  • 0.5.8                                ...           3 years ago
  • 0.5.7                                ...           3 years ago
  • 0.5.6                                ...           3 years ago
  • 0.5.5                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.3                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 15
Last Month 16
Dependencies (3)

Copyright 2014 - 2016 © taobao.org |