Skip to content

Instantly share code, notes, and snippets.

@nic nic/setup_relay.js
Last active Dec 15, 2017

Embed
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: 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
You can’t perform that action at this time.