Skip to content

Instantly share code, notes, and snippets.

@nic
Last active December 15, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nic/25a578af25a1d5f600087447aa3ba56d to your computer and use it in GitHub Desktop.
Save nic/25a578af25a1d5f600087447aa3ba56d to your computer and use it in GitHub Desktop.
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