Skip to content

Instantly share code, notes, and snippets.

@keichan34
Created July 23, 2018 11:56
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 keichan34/2fb3f10b60ea8dc8200116f5d1609334 to your computer and use it in GitHub Desktop.
Save keichan34/2fb3f10b60ea8dc8200116f5d1609334 to your computer and use it in GitHub Desktop.
hacking CRA to work with babel-plugin-relay
{
"scripts": {
"build": "node ./setup && react-scripts build"
}
}
const fs = require('fs');
const path = require('path');
const file = path.resolve('./node_modules/babel-preset-react-app/index.js');
var text = fs.readFileSync(file, 'utf8');
if (!text.includes('babel-plugin-relay')) {
if (text.includes('const plugins = [')) {
text = text.replace(
'const plugins = [',
"const plugins = [\n require.resolve('babel-plugin-relay'),",
);
fs.writeFileSync(file, text, 'utf8');
} else {
throw new Error(`Failed to inject babel-plugin-relay.`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment