🔧 Injects babel plugins into create-react-app without ejecting.
🔧 Injects babel plugins into create-react-app without ejecting.
Run yarn add --dev inject-babel-plugins-cra
.
yarn add babel-plugin-relay babel-plugin-react-css-modules
.create a js script that injects the plugins to your app, let’s call it init.js
. e.g:
const injectBabelPluginCRA = require('inject-babel-plugin-cra');
injectBabelPluginCRA([
// add a simple plugin
{ name: 'babel-plugin-relay' },
// add a plugin with options
{
name: 'babel-plugin-react-css-modules',
options: {
generateScopedName: '[path]__[name]__[local]',
},
},
]);
start
script in package.json
to call the init.js
script first."start": "node ./init.js && npm-run-all -p watch-css start-js"
Array<{
/* plugin name */
name: string,
/* plugin options */
options?: { [string]: any }
}> = []
{
/* The path to to the babel preset file */
babelPresetFilePath?: string,
/* The string to match against before injecting the plugins */
stringMatcher?: string,
} = {
/** For older version of CRA*/
babelPresetFilePath: './node_modules/babel-preset-react-app/index.js',
stringMatcher: 'const plugins = [',
}