Skip to content

Instantly share code, notes, and snippets.

@cahnory
Last active March 5, 2018 09:58
Show Gist options
  • Save cahnory/ce6f334cdc9de280ce426910869d82bf to your computer and use it in GitHub Desktop.
Save cahnory/ce6f334cdc9de280ce426910869d82bf to your computer and use it in GitHub Desktop.
WebpackRelayCompilerPlugin
const childProcess = require('child_process');
function RelayCompilerPlugin(options) {
this.schema = options.schema;
this.src = options.src;
}
RelayCompilerPlugin.prototype.apply = function(compiler) {
const cmd = `relay-compiler --src ${this.src} --schema ${this.schema}`;
compiler.plugin('after-compile', (compilation, callback) => {
compilation.fileDependencies.add(this.schema);
callback();
});
compiler.plugin('before-compile', () => {
console.log(`RelayCompilerPlugin: ${cmd}`);
childProcess.execSync(cmd,
{
stdio: [0, 1, 2],
},
);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment