Created
July 23, 2018 11:56
-
-
Save keichan34/2fb3f10b60ea8dc8200116f5d1609334 to your computer and use it in GitHub Desktop.
hacking CRA to work with babel-plugin-relay
This file contains 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
{ | |
"scripts": { | |
"build": "node ./setup && react-scripts build" | |
} | |
} |
This file contains 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
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