Last active
March 5, 2018 09:58
-
-
Save cahnory/ce6f334cdc9de280ce426910869d82bf to your computer and use it in GitHub Desktop.
WebpackRelayCompilerPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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