Skip to content

Instantly share code, notes, and snippets.



Last active Dec 15, 2017
What would you like to do?
create-react-app + Relay Modern without Eject
#!/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:
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