Last active
December 15, 2017 13:12
-
-
Save nic/25a578af25a1d5f600087447aa3ba56d to your computer and use it in GitHub Desktop.
create-react-app + Relay Modern without Eject
This file contains hidden or 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
#!/usr/bin/env node | |
// by nic - 2017 | |
// It's 10 lines of code to prevent you to call 'yarn eject' | |
// Just call this script before start/build as in this example: https://github.com/nic/relay/blob/master/package.json#L23-L24 | |
const fs = require('fs'), | |
file = require('path').resolve('./node_modules/babel-preset-react-app/index.js'), | |
texts = fs.readFileSync(file, 'utf8'), | |
plugin = 'babel-plugin-relay', | |
pattern = 'const plugins = ['; | |
if (!texts.includes(pattern)) throw new Error(`Failed to inject babel-plugin-relay.`); | |
if (!texts.includes(plugin)) | |
fs.writeFileSync(file, texts.replace(pattern, `${pattern}\n require.resolve('${plugin}'),`), 'utf8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment